x


Collider Animation

How would i make it so that when i hit a collider, and when im in that certain collider i press the button 'h' The animation starts to go, I did try and write this code myself but it didnt work, This is my code

function OnCollitionEnter ()

{

if(Input.GetKey("h"))

animation.Play("Test Animation");

} If anybody could help or point in the right direction that would be great ? Thanks

more ▼

asked Feb 23 '12 at 01:18 PM

benjimazza gravatar image

benjimazza
102 23 34 37

You have a small typo in OnCollitionEnter..don't know if it's the same in your code but it should be OnCollisionEnter(). The OnCollisionEnter function will only be triggered that one frame where the collision is first detected i think. Maybe try setting a variable to true or false using the functions OnCollisionEnter() and OnCollisionExit().

Feb 23 '12 at 01:26 PM merry_christmas

Sorry try using the OnCollisionStay() function instead, should check every frame :)

Feb 23 '12 at 01:31 PM merry_christmas
(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

Fixed i figured it out :D

more ▼

answered Feb 23 '12 at 01:37 PM

benjimazza gravatar image

benjimazza
102 23 34 37

Can you post the final script please?, I have also been faced with this problem before.

Feb 23 '12 at 01:40 PM MithosAnnar

It is alot like What i wrote i just typed some things wrong,

// Attach this script to your object and set IsTrigger under the

//box collider :)

function OnTriggerEnter(hit : Collider)

{

animation.Play("NAME OF ANIMATION");

}

Feb 23 '12 at 02:01 PM benjimazza
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x3768
x1682
x531
x25

asked: Feb 23 '12 at 01:18 PM

Seen: 774 times

Last Updated: Feb 23 '12 at 02:01 PM