控制物体的移动与碰撞检测

using UnityEngine;using System.Collections;public class move : MonoBehaviour {GameObject go;// Use this for initializationvoid Start () {go= GameObject.Find("c4");//命名为c4的Cubego.renderer.material.color = Color.red; //将其材质设为红色}// Update is called once per framevoid 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 initializationvoid Start(){}// Update is called once per framevoid Update(){}/// <summary>/// 将碰撞到物体变为蓝色/// </summary>/// <param name="co">被碰撞到的物体</param>void onCollisionEnter(Collision co){co.gameObject.renderer.material.color = Color.blue;}}

,教育人的,激励人的,安慰人不开心的. 或者是 诗词 诗经里的..

控制物体的移动与碰撞检测

相关文章:

你感兴趣的文章:

标签云: