- Home /
On Collision Enter Press F
hey guys i have a question how do i do a Function Update(){ OnCollissionEnter(){ if inpud GetKeyDown ("F"); Animation.Play(); {
so when i enter a trigger cub with this script on it the animation will not play until i press F
Post your actual code (use the little button with 1s and 0s on it for formatting). If your code is generating compiler errors, post those as well.
Answer by Alec-Slayden · Mar 01, 2011 at 08:15 AM
OnCollisionEnter is only called the frame the collision begins. For the entirety of the collision you'll want OnCollisionStay.
If you're using a trigger, however, you may want to use OnTriggerStay
Answer by by0log1c · Apr 25, 2011 at 04:52 AM
var canAnimate:boolean = false;
function OnTriggerEnter(coll:Collider){ canAnimate = true; }
function OnTriggerExit(coll:Collider){ canAnimate = false; }
function Update(){ if(Input.GetKeyDown("f") && canAnimate){ animation.CrossFade("MyAnimation"); } }