Im making a game and I need a sprite to be able to detect what color it is touching. I know there’s a way to do it, but I’ve figured out nothing so far. Help…?
You will need OnColissionEnter or OnTriggerEnter on your sprite, choose what is best for your case, example:
void OnCollisionEnter(Collision other)
Debug.Log(other.gameObject.GetComponent<Renderer>().material.color // this line will tell you the object's color which collide to the gameObject you attached this script to
Doesn’t seem to be working. I am in a 2D game, just to make sure that isn’t the reason why it won’t work. The script runs, it doesn’t say I have any compiler errors. BTW I changed to <2DRenderer>.