In my Unity project I have an Empty GameObject which has 3 child GameObjects. The Empty GameObject is called Cable Strip
and if the camera move to a special position, I want that the material of the three child Object start to change from white to yellow and back. Unfortunately all my solutions does not work.
This is what I have so far:
using UnityEngine
public class BlinkingObject : MonoBehaviou
{
public GameObject CableStrip;
public Material white, yellow;
public GameObject camManager; //Empty GameObject with the Main Camera
private Vector3 camPosition;
bool blinkObject;
void Update()
{
if(camManager.transform.position == camPosition)
{
InvokeRepeating("Blink", 0, 1);
}
}
public void Blink()
{
Renderer[] colorCable = CableStrip.GetComponentsInChildren<Renderer>(true);
foreach (var cableChild in colorCable)
{
if(blinkObject)
{
cableChild.material = yellow;
blinkObject = false;
} else
{
cableChild.material = white;
blinkObject = true;
}
}
}
}
How can I get my gameobject to blink in a nice way?
Edit
Sorry wrong definition of does not work. The problem is, that the color changes too fast. Even if I change the seconds by InvokeRepeating
nothing changes. It still changes the color in milliseconds even if I write InvokeRepeating("Blink", 0, 10);
.
true
:camManager.transform.position == camPosition
? – derHugo