- Home /
How to make a static box display message on collision
So I have a box object that when the character controller collides with I want to display a message above it. After doing some research I have found that it seems like typically only the object in motion can do the collision detection. Is there any way around this? or can I detect the collision with the CC and then call a function to change (read make appear) the text on my GUI text object?
Answer by robertbu · Mar 24, 2014 at 03:47 PM
With a character controller, you can detect the collision with with OnControllerColliderHit(), and yes that callback has to be on a script on the character controller. You can communicate that hit to the other object by getting a component on that object or by sending that object a message to that object. Something like:
function OnControllerColliderHit (hit : ControllerColliderHit) {
var myScript : MyScript = hit.collider.GetComponent(MyScript);
myScript.doDisplay = true;
}
Info on accessing other game objects:
http://unitygems.com/script-interaction-tutorial-getcomponent-unityscript/
http://docs.unity3d.com/412/Documentation/ScriptReference/index.Accessing_Other_Game_Objects.html
Your answer
Follow this Question
Related Questions
the most efficient way to detect colision between objects in a large scene (Strategy Game) 1 Answer
How do I allow an object pass through a wall/object of the same colour/material? 2 Answers
My Javascript collision isn't being detected, please help. 0 Answers
Make invisible wall appear visible upon collision/detection 1 Answer
Rigid Body Collision Detection 1 Answer