J's Study log

[Unity] Camera Work 본문

Computer Language/Unity

[Unity] Camera Work

정우섭 2019. 2. 25. 05:32

To make camera follow an object in Game View, you have to make a script and apply to Main Camera.

 First you have to declare a member variable which type is GameObject. For example, when I declare the variable like this



By using it, you can input real object's location to 'ball' by 'GameObject.Find("  ");' command.



The location of object 'Ball' will be inputted to variable 'ball' when the game starts. By coding Update() function as picture



Highlighted transform.position calls the location of objects that this script is applied. 'new Vector3(x,y,z)' make a vector which have 'x,y,z' components. By substitution of 'ball.transform.position.y + 3' in 'y' value and 'ball.transform.position.z - 14' in 'z' value, Main Camera will follow the ball in the game.

'Computer Language > Unity' 카테고리의 다른 글

[Unity] Input keys  (0) 2019.02.25
[Unity] Input Arrow Keys  (0) 2019.02.25
[Unity] GetComponent  (0) 2019.02.23
[Unity] Script  (0) 2019.02.23
[Unity] Physics Material  (0) 2019.02.21
Comments