UnitySimpleBallRollingGame Lesson2 SetupCamera - jasonweibel/HyperStream-Unity GitHub Wiki
Hyperstream : Unity Simple Ball Rolling Game: Lesson 2 - Setup Camera
-
Open Unity project started with Unity Simple Ball Rolling Game: Lesson 1 - Setup Sphere and Terrain
-
Add a New Script Component to the Main Camera
-
Select the Main Camera from the Hierarchy window.
-
Click on Add Component button and select New Script.


-
Open new CameraController script located in the Asset window with Visual Studio Express.
-
Edit CameraController script.
SphereController
using UnityEngine; using System.Collections;
public class CameraController : MonoBehaviour { public GameObject Player; private Vector3 _offset;
void Start() { _offset = transform.position - Player.transform.position; } void LateUpdate() { transform.position = Player.transform.position + _offset; }}
-
Associate Sphere to Player field in Camera Controller
From the Hierarchy window select the Sphere. Drag the selected Sphere into the Player field of the Camera Controller Script.
-
-
Using Scene drag camera so it shows the Sphere in the Camera Preview window.

-
Run project
Attachments:
image2017-5-24_8-33-13.png (image/png)
image2017-5-24_8-30-37.png (image/png)
image2017-5-24_8-29-14.png (image/png)
image2017-5-24_8-28-28.png (image/png)
image2017-5-24_8-21-47.png (image/png)
image2017-5-24_8-20-42.png (image/png)
image2017-5-24_8-14-14.png (image/png)
image2017-5-24_8-11-49.png (image/png)
image2017-5-24_8-9-31.png (image/png)
image2017-5-24_8-8-10.png (image/png)
image2017-5-24_8-6-26.png (image/png)
image2017-5-24_8-5-32.png (image/png)
image2017-5-24_8-4-29.png (image/png)
image2017-5-24_8-1-11.png (image/png)
image2017-5-24_7-58-53.png (image/png)
image2017-5-24_7-56-3.png (image/png)
image2017-6-1_8-5-26.png (image/png)
image2017-6-1_8-5-49.png (image/png)
image2017-6-1_8-10-12.png (image/png)
image2017-6-1_8-12-21.png (image/png)