PlayController.cs源码清单
using UnityEngine; using UnityEngine.UI; using System.Collections; public class PlayerController : MonoBehaviour { public float speed; public Text countText; public Text winText; private Rigidbody rb; private int count; void Start() { rb = GetComponent<Rigidbody> (); count = 0; countText.text = "Count:" + count.ToString (); winText.text = ""; SetCountText(); } void FixedUpdate() { float moveHorizontal = Input.GetAxis ("Horizontal"); float moveVertical = Input.GetAxis ("Vertical"); Vector3 movement = new Vector3 (moveHorizontal, 0.0f, moveVertical); rb.AddForce (movement * speed); } void OnTriggerEnter(Collider other) { if (other.gameObject.CompareTag ("Pick Up")) { other.gameObject.SetActive(false); count = count + 1; SetCountText(); } } void SetCountText() { countText.text = "Count:" + count.ToString (); if (count >= 10) { winText.text = "You Win"; } } }
CameraController.cs源码清单
using UnityEngine; using System.Collections; public class CameraController : MonoBehaviour { public GameObject player; private Vector3 offset; // Use this for initialization void Start () { offset = transform.position - player.transform.position; } // Update is called once per frame void Update () { transform.position = player.transform.position + offset; } }
using UnityEngine; using System.Collections; public class Rotator : MonoBehaviour { // Update is called once per frame void Update () { transform.Rotate (new Vector3 (13, 30, 45) * Time.deltaTime); } }