- Home /
Question by
danfiala23 · Oct 27, 2019 at 10:22 PM ·
c#collidermeshrenderer
Set material of child that enter the collider.
Hi i need little help. This is my code: Transform hex; public Material Dirt; public Renderer[] childColors;
public void Start()
{
}
void OnTriggerEnter(Collider other)
{
if (other.gameObject.tag == "Grass")
{
//MeshRenderer childColors = other.GetComponentInChildren<MeshRenderer>();
//hex = other.transform.GetChild(0).GetChild(0);
foreach (Renderer color in childColors)
{
color.material = Dirt;
}
}
}
But idk what I should do.
Comment
Answer by Lazdude17 · Nov 01, 2019 at 04:15 AM
void OnTriggerEnter(Collider other) {
if (other.gameObject.tag == "Grass")
{
//Obviously switch DIRT out for your variable containing the appropriate material
gameObject.GetComponent<MeshRenderer>().material = DIRT;
}
Your answer