Hi All,
I’m new with Unity3D and I have a question:
I would like to be able to “highlight” an object in my scene when the mouse hovers on top of it and then unselect it when the mouse leaves it. After that, I would like to change the texture of the material that is used by this object.
I wrote a script for highlighting/unhighlighting the object such as the following:
void Start()
{
startColor = renderer.material.GetColor("_Color");
}
void OnMouseEnter()
{
renderer.material.SetColor("_Color", Color.yellow);
}
void OnMouseExit()
{
renderer.material.SetColor("_Color", startColor);
}
I have assigned this script to the object and everything works fine.
This object uses a material that has a texture assigned to it. The material is used by some other objects in the scene as well (also able to be highlighted/unhighlited).
The problem is that I have another script that, when the user presses a GUI button, changes the texture of this material like this:
woodMaterial.SetTexture("_MainTex", woodTexture"); // where woodMaterial is of type Material and woodTexture is the texture that I want to assign to the material.
This script is assigned to the Camera that overviews the objects in the scene.
If I highlight the object, highlighting works OK but when pressing the button to change the texture, the texture is not changed.
If I comment out the lines that manipulate the color in the highlight script, the texture is set successfully when pressing the GUI button for changing the texture.
The material is assigned through the Inspector and I am using Unity3d v4.0
Any ideas what is going on ?
I noticed that even the first line “startColor = renderer.material.GetColor(”_Color"); " causes the SetTexture to not work anymore.
Thanks for any hints or help!