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

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;
}