- Home /
Is there a way I can Trigger an Animation by Not Colliding with anything?
Hi Everyone it's me again, I'm getting pretty Attached to Unity lately But I've Come across a dud, Lately I've been trying to Make it that my Player would Trigger an Animation whenever It Has No Collision happening, So Basically what I'm saying is like a Mid-air Deployement for the Animation, But I'm stopped here I've thought up until now On ways for this.Nothing yet, I completely am Stuck on this, By Far I Could Use a script to help me and Fix that, So If anyone can Find a way for that (other than already knowing), Please Inform of it to me.
Thanks In Consideration -Leon
You have to start the animation with something. I have come so far with using a key, a trigger, a collider, a timer, proximity, a gui button or mouse enter. You can always loop you animation for ever from the beginning by modifying the animation properties in the inspector.
Doesn't really help you know, I made this so i would have to avoid making it that i have a different animation on EVERY object in the game on Collider, Wouldn't that just take all my time? I've got only 5 hours a day of free time and I do alot of things in that time, No time for doing that, I just want a way around that.
I mean just saying Trigger Exit wouldn't really help me, I mean as for this bieng an Answer usually I would expect a way of actually Working out how to use these answers, So I need to know how i can use this "Trigger Exit" Whether through script or not.
Answer by Azterix · Apr 18, 2010 at 04:04 PM
I would set up a collider counter on the object that you want to animate when not colliding. When the object gets collider/trigger animations, increment the counter. When an object ends collision/exits the trigger, decrement the counter. When the counter is at zero and is added to, stop the animations. When the counter decrements back to 0, start the animation again.
Here's some pseudo-code to show what I mean (C#):
using System; using UnityEngine;
public class AnimateNoTriggers : MonoBehaviour {
private int collisionCounter = 0;
public Animation myAnimation;
void Start(){ myAnimation.Play("NotCollidingAnimation");
}
void OnTriggerEnter(Collider c){ if(collisionCounter == 0){ animation.Stop();
} collisionCounter++; }
void OnTriggerExit(Collider c){ collisionCounter--; if(collisionCounter == 0){ myAnimation.Play("NotCollidingAnimation"); } } }
Your answer
Follow this Question
Related Questions
Play sound on trigger, sound is coming from the trigger 1 Answer
Script on moving object doesn't work? 1 Answer
Activating One Part of An Animation 2 Answers
Initiate Animation 0 Answers
play animation on keypress if in range 3 Answers