Quantcast
Channel: Questions in topic: "javascipt"
Viewing all articles
Browse latest Browse all 1875

[Logical Error] Select a game object and perform actions using GUI.Button

$
0
0
I am currently working on a strategy game and I want to preform actions using **GUI.Button** on game objects. I am using **ray cast** and **mouse click** to select the object however when I click on GUI.Button to take out another action the button disappears. **I want to use that button to open up another GUI.Box to show some descriptions.** I know why the button is disappearing, it is because I am projecting the ray cast to my button clicks in the update function but how can I avoid this? should I use another way of selecting objects instead of ray cast or else? Here is my script: #pragma strict @HideInInspector var isCalled:int = 0; @HideInInspector var scWidth:int = 0; @HideInInspector var scHeight:int = 0; function Start () { scWidth = Screen.width; scHeight = Screen.height; } function Update () { if (Input.GetMouseButtonDown(0)) { var ray : Ray = Camera.main.ScreenPointToRay (Input.mousePosition); var hit : RaycastHit; if (Physics.Raycast (ray, hit)) { if (hit.collider.tag == "House") { isCalled = 1; } else{ isCalled = 0; } } } } function OnGUI(){ if(isCalled==1) GUI.Button(Rect(scWidth/2,(scHeight/2)+(scHeight/4),120,120), name); }

Viewing all articles
Browse latest Browse all 1875

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>