change color with collision

Hello

I am new to unity…

I am trying changing color of one object when there is colission.
This is my code

void OnCollisionEnter (Collision col)
{

if (col.gameObject.name== “ground”)
{

GetComponent().materials[0].color = Color.red;
}
}
}

Thanks for help :slight_smile:

OK, so what’s wrong?

I assume you’ll need something like col.gameObject.GetComponent().materials[0].color = Color.red;

Looks like you’re new here, I’d recommend Roll a Ball here: https://unity3d.com/learn/tutorials

Also this is the Unity Editor and General Discussion part of the forum. Your question should have been posted in the Scripting section of the forum. Also, please insert code with the “Insert” button when posting. Keeps things looking good :slight_smile: