Hello Everyone, I have a scenario where player clicks on one of the objects and the respective boolean variable selected becomes true. My issue is, when the player clicks on another object of same class, which spawns a sec later, Its respective boolean selected also becomes true but the previous object boolean selected also remains true but I want only one boolean to be true at a given time. I tried OnMouseUp() & OnMouseUpAsButton() but no luck. Please help. Thanks Regards, Bhanu
When you select something, save the object selected. When you select another one, deselect the old one. That's the theory...
Ops! Sorry... I was reading StarManta asking for code and thought "Code???" was the answer of Bhanu3d.
You could have something in the update() function like so: Code (CSharp): if(firstBool == true) { secondBool = false; } else { firstBool = true; secondBool = false; } I have no idea if this would work. I am only learning C# through trial and error.. In theory it should work..
Hello Guys, I am sorry for the late reply but the code is as follows. void OnMouseDown() { selected = true; } Now, that script is attached to enemy object and enemies spawn continuously. What I want is, if enemy1 selected, selected of that particular enemy becomes true leaving rest false which is perfect but when I select enemy2, its selected becomes true as well but I want the enemy1 selected to be back to false again making only selected enemy's bool variable true but the rest false. Hope this helps. Thanks Regards, Bhanu
Try this: Code (CSharp): using UnityEngine; using System.Collections; public class SelectOne : MonoBehaviour { static public SelectOne Current; public bool Selected = false; void OnMouseDown() { if (Current != null) Current.Selected = false; Selected = true; Current = this; } }
Hello Guys, Both of you were right. It worked perfectly and I thank you guys very much. Regards, Bhanu
Hello Guys, I am tying to spawn a gameobject every 5 secs and the gameobject should spawn in 5 different x positions randomly and only between a specified 5 positions and I tried Random.range (5 , 25) but thats not what I am looking for. Basically, I want to spawn in 5 , 10 , 15 , 20 , 25 x positions randomly choosing one of those 5 but not between 5 & 25. Please help. Thanks Regards, Bhanu
Doesn't this give me the same unwanted result? The Random.range chooses any value between 5 & 25, take 9 , 11 , 17, etc for example but I don't want any of these values. I hope my problem is more clear now. Thanks
The random range chose any value between 1 & 5. I think you do better just trying for yourself, because it's only one line of code... Edit: Indeed I was thinking about INT not FLOAT range. I just discovered that the INT range is exclusive so you have to do: Random.range (1, 6) * 5
Hello Guys, Does anyone know how to integrate Google+ or Facebook or Twitter or all the three using Unity instead of Eclipse? Thanks Regards, Bhanu
Hello Hariavm, Thanks for the FB pack but can you please explain how to use this package? When I simply run the scene FBCheck, A webpage opens with an error "This dialog has been passed a bad parameter." .Thanks a lot Regards, Bhanu