Changing colour of object once collided

Hi, I was wandering if anyone could help me solve this. I want my object, which is a block is this case, to turn red once hit with a bullet. I’ve set up the collision code, however I don’t know what code to use for it to change color. Any help would be appreciated :slight_smile:

#pragma strict

function Start () {


function Update () {


function OnCollisionEnter(objCollidedWith : Collision) {

if(objCollidedWith.collider.tag == "ammo")
	Debug.Log("block detecting collision by " +objCollidedWith.collider.tag);
//Debug.Log("block detecting collision" +objCollidedWith.collider.tag);


Here try this:


objCollidedWith.collider.GetComponent<MeshRenderer>().material.color =;


objCollidedWith.collider.GetComponent(MeshRenderer).material.color =;

Same as above but use GetComponent<Renderer> instead of MeshRenderer.

someGO.GetComponent<Renderer>().material.color =; //C#

someGO.GetComponent(Renderer).material.color =; //uJS

This will change the color to red for any GO. Replace someGO with your gameObject variable.