- Home /
How do NOT animated an object when created?
I have some leaves on a tree that are animated when they fall but I don't want them be animated when they're just sitting there in the tree. I've had this issue with so many game object. I tried unchecking "always animate" but it still starts out animated. Do I have to make an animation state with 2 sprites that are the same as the default sprite? That seems a little inefficient.
you have to call animation state only when they fall so what's going on in your code ?
Answer by Bofu189AD · Mar 20, 2016 at 09:27 PM
public class LeafFall : MonoBehaviour {
bool falling = false;
float fallSpeed = .5f;
float LR_Alternate_Speed = 5f;
Animator FallAnim;
bool LR_fall;
//Starts the fall at Invoked time
void time_to_fall()
{
falling = true;
}
//I have a catcher under the tree for the leaves to land on.
void OnCollisionEnter2D()
{
falling = false;
FallAnim.SetBool("Fall", false);
}
//Decides whether the leaf will drifet left or right(alternates back n forth as it falls)
void fall_LR_Displacement()
{
if (LR_fall)
{
LR_fall = false;
}
else
{
LR_fall = true;
}
}
//Invokes when the leaf will fall and sets the left/right drfit.
void Start () {
Invoke("time_to_fall", Random.Range(1f,333f));
FallAnim = GetComponent<Animator>();
InvokeRepeating("fall_LR_Displacement", 1, 1);
}
void Update () {
if (falling)
{
transform.Translate(-Vector3.up * Time.deltaTime * fallSpeed);
//this for the animation. It starts out in an animation state which is just the same
// two spites to make it look like it's not animated. This is all I have in my code concerning animations.
FallAnim.SetBool("Fall", true);
if (LR_fall)
{
transform.Translate(Vector3.right * Time.deltaTime);
}
else
{
transform.Translate(-Vector3.right * Time.deltaTime);
}
}
}
}
Your answer
![](https://koobas.hobune.stream/wayback/20220612071947im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Rotate an animated gameobject (2D) 1 Answer
Jump Delay Animation Solution 0 Answers
Unity 2D My animator won't transition between states? Any help would be extremely helpful 0 Answers
Where could I start with making a level editor where you can create your own terrain in Unity 2D? 0 Answers
How to flip hitboxes if my 2D Sprite is Flipped in AnimationsEditor ? [Unity2D] 1 Answer