- Home /
Trigger collision with Player won't work
Hello! :D Im Quite New Here but i've actually Started Scripting UnityScript! :D But there is a Problem with this script somehow. it won't work! I have 1 Script that changes the GUI Text when The Player Collid with the "Box". but somehow. It won't work :(
Any Ideas?
Script:
var targetGuiText : GUIText;
function OnControllerColliderHit(collision:Collision)
{
if(collision.gameObject.tag == "Player")
{
targetGuiText.text = "A Way out!";
yield WaitForSeconds(3);
targetGuiText.text = "There must be a way out..";
yield WaitForSeconds(3);
targetGuiText.text = "But where?";
yield WaitForSeconds(2);
targetGuiText.text = "";
}
}
Answer by xtremepman · Jul 26, 2012 at 08:34 PM
Use OnCollisionEnter and try attach the script to the player.
I had a similar problem and it worked for me. :D
Answer by eshonbel · May 02, 2014 at 07:36 AM
function OnCollisionEnter(collision : Collision){
Your stuff here
}
Make sure you attach a collider/gravity ignoring rigidbody to the item colliding. Also, attach one to the other object. If you want to be able to go through the object but still say the things, change it to OnTriggerEnter and make sure the collider for that object is set to Trigger.
Your answer
Follow this Question
Related Questions
Help with making a triggered gui message 1 Answer
Make text appear when object is clicked 2 Answers
gameObject.enabled is not working 1 Answer
Triggering GUI Button from collision with GameObject 2 Answers
GUI text like GTA 2 Answers