Game Development Reference
In-Depth Information
Finally, apply the following code sample 9-1 to the Skybox parent object to create its
rotation behavior and to align it continuously to the camera position. This ensures
that the Skybox is always centered on the camera wherever it travels in the scene:
01 //--------------------------------------------------
02 using UnityEngine;
03 using System.Collections;
04 //--------------------------------------------------
05 public class SkyBox : MonoBehaviour
06 {
07 //--------------------------------------------------
08 //Camera to follow
09 public Camera FollowCam = null;
10
11 //Rotate Speed (Degrees per second)
12 public float RotateSpeed = 10.0f;
13
14 //Transform
15 private Transform ThisTransform = null;
16 //--------------------------------------------------
17 // Use this for initialization
18 void Awake () {
19 ThisTransform = transform;
20 }
21 //--------------------------------------------------
22 // Update is called once per frame
23 void Update () {
24 //Update position
25 ThisTransform.position = FollowCam.transform.position;
26
27 //Update rotation
28 ThisTransform.Rotate(new Vector3(0,RotateSpeed *
Time.deltaTime,0));
29 }
30 //--------------------------------------------------
31 }
32 //--------------------------------------------------
 
Search WWH ::




Custom Search