Hi
I have made a built in array which consists of materials. I have set it up so my gameobject is a different material each time the game is played.
What I need to check though is what slot in the array my gameobject is currently in and if its possible change the tag of the object when its in a certain slot. For example this code below brings up an obvious error but it explains in simple terms what I want to do…
if ( gameObject.renderer.material = colourChanges[0] && collider.gameObject.CompareTag("Red Player Weap"))
{
System.Random random = new System.Random();
gameObject.renderer.material = colourChanges[random.Next(0, colourChanges.Length)];
print ("I have been hit by the correct colour " + collider.gameObject.tag);
}
I am trying to say that if the enemy is currently in slot [0] of my array and its hit by something with correct tag - do something. However the error here is that I cannot…
“Cannot implicitly convert type bool' to UnityEngine.Material’”
Which makes sense but I have no idea how to solve my issue. All I want to do is say when the enemy is this material/in this slot in the array then do this.
Any help is much obliged as this has been wrapping my brain for hours now. Seriously people any help is appreciated thank you ![]()
What is in the colourChanges array? Is it a material? It's more natural to compare the materials by their names. And you are assigning, not comparing the materials in your if statement. So something like this should be more convenient: 'gameObject.renderer.material.name == colourChanges[0].name' .
– bompi88