|
i want my character to use the punch animation on colliding with the player but its not working this is the script Myself is the main object which have this trigger so i set this boolean function that if it will collide with the player the boolean will be 1 and in the update function i used this boolean function to run the animation on the main Object. its not working. whats wrong in it?
(comments are locked)
|
|
OK, this script needs a bit of cleaning up. First of all, don't use CompareTag, just look for other.gameObject.tag and determine if it's "Player". Second of all, you will instead want the object with the "Player" tag to have isTrigger checked. Third of all, you don't need to specify the gameObject your script is attached to, because the compiler defaults to it if a specific object is not given. Therefore, your "Myself" variable is redundant. Also, you should try using camelCase for variable names so that they show correctly in the inspector. So like this: I believe that should work. By the way, attackOrNot isn't a boolean, it's an int. :P Hope that helps, Klep i know its an int o-o but i was using it as a boolean function like 0 or 1 and I dont want the main object to be triggered x-o i just want to put this script on a trigger which is a child of the main object and its an empty Object im just using it as a box collider trigger
Apr 08 '12 at 07:38 AM
OzzyRawrz
OK, so "Myself" was actually an empty child of the gameObject with script attached? And you had it as the trigger? Well, that still wouldn't work, because "other" is the collider with the trigger. The gameObject with the "Player" tag would have to have the trigger. I'll edit "Myself" back in ... I didn't realise it was a child.
Apr 08 '12 at 07:48 AM
Kleptomaniac
nothing changed x-o the same thing i did... its not working either ._.
Apr 08 '12 at 07:53 AM
OzzyRawrz
So 1) Is there actually an animation with the name "punch" (case-sensitive) on your Myself gameObject? 2) Try animation.Play("punch") instead of Crossfade("punch") and see if that works. 3) Did you set the trigger up on your "Player" object instead and see if that did anything different? 4) Try chucking a Debug.Log inside your OnTriggerEnter and see if it actually gets past there.
Apr 08 '12 at 07:59 AM
Kleptomaniac
well while playing the game i saw that the AttackorNot int Number was changed on Collider with player from 0 to 1. but the animation is just not running
Apr 08 '12 at 07:59 AM
OzzyRawrz
(comments are locked)
|

Is the collider marked as "IsTrigger"? Do you have a rigidbody on one of the components? A characterController?
yes it is marked as trigger and it have the rigidbody component
I have 2 remarks on Kelptomaniac's note: 1. Use CompareTag instead of the == operator. It is faster and does not allocate memory like regular string comparisons. Could be noticeable when doing allot of such comparisons, so you original take is good. Better to get use to it anyways. 2. It is also a good practice to allocate a reference to myTransform, as it is also a bit faster then doing repeating calls to gameObject.transform (or transform which is the same). What you could do, to make it a bit more simple, is myself = transform in the Awake() or Start() functions.
Have you tried to automatically play the punch animation when you run the game? So to make sure you don't have a more basic problem?
Thanks, @guyt. I didn't actually realise what CompareTag did until I just looked up the docs now. I'll make sure to use this from now on. :)