Hello,
i have a prefab of my alien enemy. During the game i spawn these aliens in waves like:
GameObject clone = Instantiate(enemy_prefab, Spawnpoints_.transform.position, Spawnpoints*.transform.rotation) as GameObject; *_
++enemyCnt;
clone.name = “Alien” + enemyCnt;
During the game i need to change the material of some aliens, but everytime i change one, the material of ALL aliens in the scene changes. I really don’t know how to handle this since i try it for a very long time now. It is no problem to change the color of a single alien, i have just problems in changing the materials.
Thank you for your answers!
*edit:
The idea behind the game is, that the enemies are invisible. You have a gun with two modes - deadly and paint. It works to map the paint onto the aliens when the renderer is off. So when i hit an alien i want it to flicker so the player can see the shape of it. Therefore i made a glass-like material. The actual problem is, when i start the flicker method of an alien - all aliens are flickering. Here is the code i wrote:
In Update Method:
if(flickerSequence > 0)
{
flickerTime -= Time.deltaTime;
if(flickerTime <= 0)
{
if(flickerSequence % 2 == 0)
setMaterial(MATERIAL.INVISIBLE);
else
{
if(!DEBUG_MODE)
setMaterial(MATERIAL.NONE);
else
setMaterial(MATERIAL.DEBUG);
}
flickerTime = FLICKER_INTERVAL;
–flickerSequence;
}
}
When i want it to flicker i set flickerSequence to the value how often i want it to flicker. This is how the material is changed (or the visibility state):
public void setMaterial(MATERIAL type)
{
//Debug.Log("Switching alien material of " + name);
switch(type)
{
case MATERIAL.DEBUG:
renderedObject.renderer.material = debugMaterial;
renderedObject.renderer.enabled = true;
break;
case MATERIAL.INVISIBLE:
renderedObject.renderer.material = invisibleMaterial;
renderedObject.renderer.enabled = true;
break;
case MATERIAL.NONE:
renderedObject.renderer.enabled = false;
break;
}
actMaterial = type;
}