- Home /
This melee damage detector won't work...
Okay, I'm still not sure what doesn't work but I know that the objects are not detecting the trigger for some reason so I'll just ask if there's anything wrong with these few lines.
function OnTriggerEnter(that : Collider) {
Debug.Log("OnTriggerEnter() was called");
}
This should send a message to show that OnTrigger was called but it won't for some reason, it won't happen. This is perplexing because in a script I have that monitors health, the exact same line is used and works perfectly on the player, but when I put this on another object set to "isTrigger" it does nothing.
also I got this weird message in the debug log. It isn't an error message so I can still run the scene but I don't know what it is and I haven't seen it before I've had this problem so maybe that's it. the error message reads: Default GameObject Tag: melee zone already registered
$$anonymous$$OST CO$$anonymous$$$$anonymous$$ON CAUSE: one of the objects $$anonymous$$UST have a rigidbody for this to work
that can't be though... because this was taken from my health stat script which works just fine and neither the player or health pack have a rigidbody component
If BOTH objects have a trigger, you need a rigidbody..
BOTH ojects have trigger, and I tested out your suggestion anyway and it didn't work. I think it might be a compiling error. The theory is down straight and the above lines work in my other scripts. But I'll try one more thing and see if it works... but, thanks, you really have been helpful with this.
Answer by Seth-Bergman · Jul 20, 2012 at 03:30 AM
For OnTrigger to work, the object with this script must be set to "isTrigger". Otherwise use OnCollisionEnter instead
EDIT:
OH, got it:
change if(Input.GetButtonDown("Hit")...
to
if(Input.GetButton("Hit")
GetButtonDown only returns true the first frame the button is pressed
EDIT2:
Since the question has now changed, here's the new answer-
If BOTH objects are set to isTrigger, one of them will need a rigidbody as well.. OR, just use OnCollisionEnter instead
http://docs.unity3d.com/Documentation/Components/class-BoxCollider.html
note the section on triggers
I'm sorry, but I already know this, the object is already set to istrigger... But thanks anyway.
add this line at the top:
function OnTriggerEnter(other : Collider){ //when you walk into
Debug.Log(other.tag); //send a Debug Log
if (other.tag == "uppermz"){ //and if other's tag is "uppermz";
etc...
as long as the other object in the collision has a collider, and is tagged correctly, this should work.. The Debug Log may provide a clue..
forget that,
change if(Input.GetButtonDown("Hit")...
to
if(Input.GetButton("Hit")
GetButtonDown only returns true the first frame the button is pressed
updated my answer above
Your answer
Follow this Question
Related Questions
AnimationEvent, Collider, OnTriggerEnter logic? 0 Answers
Melee attack comblat 1 Answer
Fog On and Off Script Help! 2 Answers
Accessing variables in enemy. 2 Answers
Creating a collider in a gameObject using only code 1 Answer