Control of object movement and collision detection

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.