- Home /
Checking materials that were assigned at runtime
I'm attempting to check the material of a prefab. As the prefab is generated, it is randomly assigned a material from a list of available materials. For the purposes of testing, the list is set to only 1 material.
I've tried multiple ways to compare the material of the prefab, but no matter what I do, the condition never seems to be true. I highlighted the condition in question.
function OnCollisionEnter (col:Collision)
{
GetComponent.<AudioSource>().PlayOneShot(paddleHitSound,0.5);
if (col.gameObject.tag=="powerUp") //check powerups
{
Debug.Log("Confirmed contact with powerup");
var powerController:powerUpScript; //set up script controller for powerup
powerController = col.gameObject.GetComponent(powerUpScript);
**if (powerController.rend.material == powerController.power1)//compare material of powerupball to list of available powers**
{
Debug.Log("Confirmed contact with power1");
//Do stuff
}
else
{
Debug.Log("This should not happen");
//do something else
}
//more stuff
}//End of Check PowerUp
}
Your answer
![](https://koobas.hobune.stream/wayback/20220612112332im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Problem with a Unity Scripting example from the scripting manual! 0 Answers
I'm having a problem with getting a door to open 1 Answer
Raycast.normal vs collision.contacts[].normal which is better? 0 Answers
The method StartHost() didn't work why ? 0 Answers
How to rotate spine by the script, while an animation from the animator is playing? 0 Answers