标签:
using UnityEngine; using System.Collections; public class move : MonoBehaviour { GameObject go; // Use this for initialization void Start () { go= GameObject.Find("c4"); //命名为c4的Cube go.renderer.material.color = Color.red; //将其材质设为红色 } // Update is called once per frame void Update () { //在每一帧中都实时地检测有没有按下键盘,并通过W、S、A、D键控制c4移动的方向 if (Input.GetKey (KeyCode.W)) { go.transform.Translate(-5 * Time.deltaTime,0,0,Space.Self); } if (Input.GetKey (KeyCode.S)) { go.transform.Translate(5 * Time.deltaTime,0,0,Space.Self); } if (Input.GetKey (KeyCode.A)) { go.transform.Translate(0,0,-5 * Time.deltaTime,Space.Self); } if (Input.GetKey (KeyCode.D)) { go.transform.Translate(0,0, 5* Time.deltaTime,Space.Self); } } }
using UnityEngine; using System.Collections; public class jiance : MonoBehaviour { // Use this for initialization void Start() { } // Update is called once per frame void Update() { } /// <summary> /// 将碰撞到物体变为蓝色 /// </summary> /// <param name="co">被碰撞到的物体</param> void onCollisionEnter(Collision co) { co.gameObject.renderer.material.color = Color.blue; } }
标签:
原文地址:http://blog.csdn.net/lindonglian/article/details/44778071