2017년 1월 4일 수요일

Unity - 3 - (C# 1) Way to write simple scripts and basically Unity API

Here is a C# code to use in script
I'll explain about it


using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class PlayerController : MonoBehaviour {

    private Rigidbody rb;
    //Declare instance of Rigidbody

    void Start () {
        rb = GetComponent<Rigidbody>();
}

    void Update()
    {
        float moveHorizontal = Input.GetAxis("Horizontal");
        float moveVertical = Input.GetAxis("Vertical");
        //Declare variable that record input from the axises 

        Vector3 movement = new Vector3(moveHorizontal, 0.0f, moveVertical);
        rb.AddForce(movement);
        //Execute function for addition force
    }
}


First 

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

These codes mean using each namespace.
The namespace is set of data structures like class, interface, struct and etc ... so we can use data structures which is included each namespace by calling each namespace.
But it is not very important factor at writing basically unity script because it's automatically generated when create 'new script'



Second 

public class PlayerController : MonoBehaviour { … }

This code means, you know, define class 'PlayerController' which inherit class 'MonoBehaviour'
obviously this code is also automatically generated



Third

    private Rigidbody rb;

It's a code to generate instance
The instance is ... a kind of logical object in programming defined by class
so ... to explain figuratively ... class is document form and instance is document which used form.
In this case, declare instance 'rb' which is formed by class 'Rigidbody' (and the 'Rigidbody' is defined in namespace 'UnityEngine')


Fourth

    void Start () { … }
    void Update() { … }

Although It is also automatically generated , it is very important factor of script.
These arrange execution timing of your code
there is some function about execution timing

initiation methods ( called when script is initialized ) : 
Start() - is only called if the script instance is enabled
Awake() - is called before any initiation method

Update methods ( called repeatedly during running script)
Update() - is called each frame
FixedUpdate() - is called fixed framerate frame
LateUpdate() - is called after all update functions have been called 



Fifth 

        float moveHorizontal = Input.GetAxis("Horizontal");
        float moveVertical = Input.GetAxis("Vertical");

This code declare variable that record input from the each axis
GetAxis("Horizontal") get data by left·right key on keyboard or joystick
GetAxis("Vertical") get data by up·down key on keyboard or joystick



Sixth

        Vector3 movement = new Vector3(moveHorizontal, 0.0f, moveVertical);
        rb.AddForce(movement);

This code also declare instance 'movement' by class 'Vector3'
The class 'Vector3' is just set of three variables like { x , y , z } .
In a same case 'Vector2' is set of two variables and 'Vector4' is set of four variables
and add force to rb !
there is four kind of ForceMode(default is Force), you know F=ma , isn't it?

Force - is F in F=ma , add continuous force to the rigidbody, using its mass
Acceleration - is a in F=ma , add continuous acclertion to the rigidbody, ignoring its mass
Impulse - is also F , but it add 'instant' force impulse to the rigidbody
VelocityChange - is just change rigidbody's velocity 

Unity - 2 - giving physical effect to the object by using script (moving objects)

1. At first, you should give physical property to the object like rigidbody which means solidate something
2. And add a script to the object by using 'Add Component' button in the lower right
3. Then you can see a generated script in the object
4. To open it , double click the script
 5. Actually, if you don't have 'Visual Studio 2015', unity load 'monodevelop' which is basic script editor of unity. but in my case , VS is more comfortable because I used it , so I'll use VS2015
6. In 'Monodevelop', you can get Unity API library by just pressing ' Ctrl and ' '
but in VS you have to find it in 'help' - > 'Reference Unity API'
7. Then by using API , you can write code for move object like that

※ The code is a little complicated, so next chapter , I'll explain about some API for beginners

2017년 1월 3일 화요일

Unity - 1 - Setting some object at scene


1. At left upper corner of hierarchy , you can find create button. then you should click it and create a plane for making ground.

2. At right upper corner of inspector which on right , you can find button seems like gear in transform item. then click it and reset transform option of plane


3. if you wanna make a sphere, you can make it in same way of making ground

4. and don't forget reset and relocate because if the sphere is reset transform, the sphere overlaps with the plane. so you need relocate it by controlling transform variables or using locating tool


5. Finally you may rename objects and must save scenes before you break the project


6. but ... you know , white ball on white ground is inconspicuous

7. in this case, you can use 'material' function which can give material property to any object

8. it is so easy to give color to material! at upper right , you can find albedo and also find color palate right of it
9. after all ... just drag it to object in scene view

Unity - 0 - How can we make project


Hello guys !! it's me Lucid 
.... then today , the first post , we will make unity project 


1. When the unity is turned on , click the new button in the upper right corner


2. Fill in the text box with what you want ( in my case, i will post that how we make roll a ball game, so i wrote 'Roll a ball' ) and set location and in this time, you don't have to care about 'organization'
and don't forget to check what you want is whether 2D or 3D


3. Finally you can see generated project

Hello Guys !! I'm Lucid Code

I'll make something(?) by using 'Unity'
this blog is made for it
then ... hmm ... 
let's get it on !