- Home /
Select Deselct a GameObject
Hey guy I'm kinda new to unity and i have this code ive been tryin to write...well basically I want to be able to select an object in game mode and its has to look like its been selected and when i click on another one, it deselects the highlighted one and selects the new one or if i click anywhere else it just needs to deselect the old one.
I was trying to come up with a code that would let me change the texture when i select an object therefore simulating the feeling of being selected and then go back to the original texture when deselected....
thank you for your time
Answer by syclamoth · Nov 14, 2011 at 09:31 PM
Well, you can use material.color to change the tint, so when you select an object (through raycasting or whatever) you would do something like this-
void SelectNewObject(GameObject newObj)
{
if(currentlySelected)
{
currentlySelected.material.color = originalColour;
}
currentlySelected = newObj;
originalColour = currentlySelected.material.color;
currentlySelected.material.color = selectedColour;
}
void DeselectAll()
{
if(currentlySelected)
{
currentlySelected.material.color = originalColour;
}
currentlySelected = null;
}
Your answer
Follow this Question
Related Questions
How can I set the GUI box to deselect after another one is selected? 2 Answers
(C#) Clicking on gameObject to select, clicking off to deselect 3 Answers
How to change selected button in EventSystem or deselect it 5 Answers
how to select and deselct an instantiated objects. 3 Answers
Deselect a selected object? 2 Answers