先来看一下效果图
这里写代码片
using UnityEngine;
using System.Collections;
public class Food : MonoBehaviour {
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
this.transform.Rotate (Vector3.up*5);
}
}
食物的代码
using UnityEngine;
using System.Collections;
public class Test : MonoBehaviour {
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
float Hmove = Input.GetAxis ("Horizontal");
float Vmove = Input.GetAxis("Vertical");
this.rigidbody.AddForce (new Vector3(Hmove*10,0,Vmove*10));
}
void OnTriggerEnter(Collider other)
{
Debug.Log("d");
if (other.gameObject.name == "Cube") {
GameObject.Destroy(other.gameObject);
}
}
// void OnTriggerExit()
// {
//
// }
// void OnTriggerStay()
// {
//
// }
}
小球的代码
using UnityEngine;
using System.Collections;
public class Gamer : MonoBehaviour {
public GameObject player;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
//this.GetComponent<Transform> ().position = new Vector3 ();
Vector3 pos = player.GetComponent<Transform> ().position;
this.GetComponent<Transform> ().position = new Vector3 (pos.x,pos.y+18.7f,pos.z-12.6f);
}
}
相机的代码