- Home /
change the wrap mode of a 2d animation
hi, i have a gameobject with an animator attached. the animator has 2 animations ("Idle" and "attack"). the problem is that i get the error
"MissingComponentException: There is no 'Animation' attached to the "EntityPlayer" game object, but a script is trying to access it. You probably need to add a Animation to the game object "EntityPlayer". Or your script needs to check if the component is attached before using it."
its important that the idle animation loops , whilst attack animation plays once , stops and then goes back to idle.I have no idea what i am doing wrong. please help !
here is a portion of the code: ( i removed everything except the parts relevant to the problem to make it easier to look at).
 using UnityEngine;
 using System.Collections;
 using System.Collections.Generic;
 public class Entity : MonoBehaviour
 {
         public GameObject GOContainingAnimator;
         Animator EntityAnimator;
         public string IdleAnimationName;
         public string MeleAnimationName;
         public string RangedAnimationName;
         public string DeathAnimationName;
         public bool EntityIdle;
         public bool EntityAttackingMele;
         public bool FriendOrEnemyInfront;
         public GameObject GOContainingAnimator;
         void Start ()
         {
                 EntityAnimator = GOContainingAnimator.GetComponent <Animator> ();
         }
         
         void Update ()
         {
                 AnimatorUpdater ();
         }
         
         void AnimatorUpdater ()
         {
                 
                 //if the entity is moving loop the idle animation, if it isnt, go through it once and then stop
                 if (EntityIdle) {
 
                         EntityAnimator.SetBool ("EntityIdle", true);
                         EntityAnimator.animation [IdleAnimationName].wrapMode = WrapMode.Loop;
                 }
                 if (FriendOrEnemyInfront && EntityIdle) {
                         EntityAnimator.SetBool ("EntityIdle", true);
                         EntityAnimator.animation [IdleAnimationName].wrapMode = WrapMode.Once;
                 }
 
                 
                 if (EntityAttackingMele) {
                         EntityAnimator.SetBool ("EntityAttackingMele", true);
                         EntityAnimator.animation [MeleAnimationName].wrapMode = WrapMode.Once;
                 } else {
                         EntityAnimator.SetBool ("EntityAttackingMele", false);
                 }
 
                 
         }
 }
Your answer
 
 
             Follow this Question
Related Questions
Conflicting Animator SetTrigger 0 Answers
pause Animation 0 Answers
Shooter 2D: Character animation only runs once 1 Answer
Is it possible to always make animations play differently? 0 Answers
 koobas.hobune.stream
koobas.hobune.stream 
                       
               
 
			 
                