Unity on machine-mouse click Cube color

Source: Internet
Author: User
Tags goto

The title is this, 3 cube is called a B C bar,

One of the points in the mouse color, such as the point of a, which becomes blue, then point in the other after the other blue, the object in the previous point, restore the original color,

I wrote the following code: I used the goto, although realized, but feel bad, some people say with recursion to do, seek guidance

Using unityengine;using System.collections; public class myscript:monobehaviour {    Private Color tempcolor;//Object Colors     Private Gameobject tempgame;//objects in the save point     private bool tempbool=true;// Control change void Update ()      {        Ray Ray = Camera.main.ScreenPointToRay (Input.mouseposi tion);        Raycasthit hit;        if (Physics.raycast (ray, out hits) &&in Put. Getmousebuttondown (0))         {            Aa:;//goto statement jump tag   &NBSP ;         if (tempbool)             {          &NB Sp     Debug.Log (tempbool);                Tempgame = HIT.TRANSFORM.GAMEOBJ ect;//Objects                  Tempbool = false;        &NBS P  }            Else {                Debug.Log (tempbool);    &NBSP ;           TempGame.renderer.material.color = tempcolor;//Last object color         &NBS P       Tempbool = true;                Goto aa;           }            Tempcolor = hit.transform.gameObject.renderer.material.co lor;//Object Color             Hit.transform.gameObject.renderer.material.color = color.blue;/ /Point object after blue        }}}

Unity on machine-mouse click Cube color

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.