Question is off-topic or not relevant
Colour Swapping Script C#
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!!!
Hi. These sorts of question are not for Unity Answers. Sadly many moderators just publish every question.
For basic beginner questions the solution is simple:
google "unity how to change color" google "unity how to check collision"
Please make sure to research your qustion before asking a new one.
Have a nice day.
Answer by juippi112 · May 09, 2016 at 08:52 PM
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.