How do I detect what color a gameobject is touching?
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..?
Answer by edwinharly · Aug 28, 2017 at 07:59 AM
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 .
$$anonymous$$ake sure that the two sprites have colliders and have the trigger box ticked.
Your answer
Follow this Question
Related Questions
Hi guys, I need help with C# Scripting using Raycast. 1 Answer
Changing Camera Background Color 1 Answer
Can not access an abstract class from another script! 0 Answers
Can't compare a string to an *? 2 Answers
Rotate Player 90 degrees about its Y axis relative to the mouse being dragged between two angles 1 Answer