Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

NGUI click on the button when the mouse events to shield the scene

Discussion in 'Scripting' started by yuhonglei, Mar 31, 2014.

  1. yuhonglei

    yuhonglei

    Joined:
    Feb 26, 2013
    Posts:
    17
    As is shown in the picture, there is a cube and a sphere in the scene, my code is as follows, to achieve the effect is when you click the scene in cube cube began to change color, hide and show the sphere when you click the NGUI button,

    The present situation is when I click on the NGUI button, also point to the scene in cube, resulting in cube also began to change color when the mouse events, how can the shielding in the scene I click on the button, let cube do not change color....
    $QQ图片20140331104232.jpg

    Code (csharp):
    1. #pragma strict
    2. var a : GameObject;
    3. var b :boolean = false;
    4.  
    5. function Start () {
    6.  
    7. }
    8.  
    9. function Update () {
    10.  
    11. }
    12.  
    13. function  OnMouseDown(){
    14.  
    15.     a=GameObject.Find("box");
    16.  
    17.     if(b == false){
    18.  
    19.         a.renderer.material.color = Color.red;
    20.         b = true;
    21. }
    22.  
    23.     else if(b == true){
    24.  
    25.         a.renderer.material.color = Color.yellow;
    26.         b = false;
    27.     }
    28. }
    Code (csharp):
    1. #pragma strict
    2. var c : GameObject;
    3. var d : boolean = false;
    4.  
    5. function Start () {
    6.  
    7.  
    8.  
    9. }
    10.  
    11. function Update () {
    12.  
    13. }
    14.  
    15. function OnClick(){
    16.  
    17.     if (d == false){
    18.  
    19.         c.active = false;
    20.         d = true;
    21.  
    22.  
    23.     }
    24.  
    25.     else if(d==true){
    26.  
    27.         c.active = true;
    28.         d=false;
    29.     }
    30.  
    31.  
    32.  
    33.  
    34. }