Actually I am working on a roll a ball game . I want to create a script on C# such that the player swaps it’s colour with the colour of object it hits . For E.G - I have 4 cubes with colours A,B,C,D . As the player hits the Cube with colour A , the Cube gets destroyed and the player gains colour A , next as the player hits Cube with colour B , the Cube with colour B gets destroyed and the player gains colour B ans so on . Help Please!!!
You just have to access your own and the collision object’s material color.
C#:
void OnCollisionEnter(Collision collision) {
if(collision.collider.CompareTag("ColorCube"))
{
GameObject go = collision.gameObject;
GetComponent<Renderer>().material.color = go.GetComponent<Renderer>().material.color;
Destroy(go);
}
}
that’s all. Attach this to your ball script or somethin.