Using unityengine;using System.collections;public class Move:monobehaviour {gameobject go;//use this for initialization void Start () {go= gameobject.find ("C4"); Cubego.renderer.material.color = color.red named C4; Set its material to red}//update is called once per framevoid update () {//To detect in real time in each frame whether the keyboard is pressed and to control the direction of C4 movement via W, S, A, D keys if (Input.getkey (K EYCODE.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>< c9/>///will collide to the object blue///</summary>// <param name= "CO" > The object to be collided </param> void Oncollisionenter (Collision Co) { co.gameObject.renderer.material.color = Color.Blue; }}
Control of object movement and collision detection