- Home /
OnTrigger* triggered only once
Hello !
I really would have preferred not to bug anyone about this problem of mine, but I really am desperate about it now. Alright, so thank you in advance for all the help you guys will provide me.
Before explaining the problem, I simply want to let you guys no I have little to none experience in Unity and Game Development altho I am a web developer. A friend of mine and I wanted to try it out using the incredible 2d Toolkit asset which is working just fine as of now.
The context of my Proof of Concept is as follow : I have a scene with 3 Sprites on it. Each one of it has a Mesh Collider and the Player has a Rigid Body. The player can move around (in a 2D manner) and my next step would have been to make impossible for the player to walk over the other sprites.
I've clicked on the 'is Trigger' option of the Box Collider panel and coded (in C#) the onTrigger events as follow :
void OnTriggerEnter(Collider trig)
{
Debug.Log("Enter");
}
void OnTriggerStay(Collider trig)
{
Debug.Log ("Stay");
}
void OnTriggerExit(Collider trig)
{
Debug.Log("Leave");
}
Everything works fine if my character enters and leaves one of the Sprite. However, if he tries to enter it again, or enter another one, none of the trigger are called again.
Trying to find a solution over the Net, but nothing could explain explicitly what my problem might be.
Thank you
aldonaletto found out it was caused by the collapse button. However I wonder why it works, because you said you are trying to make a 2D game and your code is for 3D games. Everything should be with 2D at the end: like OnTriggerEnter2D (Collider2D collider) etc... So it works? I always had problems when I was using the 3d functions...
This question was posted before the 2D mode was available in Unity - 3D physics with the Z axis frozen was the only solution for 2D games. The 2D physics engine appeared more than one year later, in Unity 4.3, and is by far the preferable choice for 2D games (much faster and lighter). The 3D and 2D engines don't talk to each other, thus only the "2D ending" functions and components must be used together in a 2D game. You can even use both engines in the same scene, but they won't interact with each other: a 3D Rigidbody won't hit a Rigidbody2D, a Collider2D won't stop a 3D regular Rigidbody, etc.
Answer by aldonaletto · Mar 04, 2012 at 07:57 PM
The code seems ok. Verify that damned Collapse button in the Console view: when it's pressed, the console doesn't print repeated messages, what usually drives programmers nuts!
Woah, that was as simple as that. I guess Unity should display at least the number of stack it got from the same message. I truly wasn't aware of this. Thank you so much, it helped me to move on :)
This button is a Devil's creation! It has fooled lots of users (me included), from noobs to experts. Number the messages is a good suggestion!
Damn, I was searching for this answer for about 20 $$anonymous$$utes now, never would have guessed it was this simple. Thank you.
How to Stop All Game Sound in All Scenes by simply pressing On/Off Button Hello I'm New in this field So please help me .. I just want to stop all music by pressing a simple button "Off" from main menu and Want to Start Again All Sound of the game By Pressing another button "On" also located on main menu ...
i designed 20 Levels,Scenes for my game and want to stop All sound of the game from main menu But i can only stop the Sound,$$anonymous$$usic that is on the main menu when i go to the next scenes,Level Sound is not $$anonymous$$ute .
I know its possible by using Void Awake() Function But i'm New So Please Give me the right solution,Logic ...Thanks
Your answer
Follow this Question
Related Questions
OnTrigger event when colliders are already touching eachother 1 Answer
Collision not detected 3 Answers
Collision Detection without a RigidBody 2 Answers