unity – Assist with taking part in animation


I am making an attempt to play animation that adjustments the facial expressions of characters from a Sport Supervisor however having some hassle. When the routine or methodology is known as from inside the class itself, it really works superb. Nonetheless, when invoked from the Sport Supervisor, the expressions don’t change. Yet one more odd factor about that is that Motion animations, i.e. clapping or leaping, e.g. works superb when invoked from the Sport Supervisor. Here is a pattern of the code:

// Referred to as from Sport Supervisor:
 StartCoroutine(sceneController.setPlayerMood(string sMood, string sPlayer));

// Referred to as inside Class
StartCoroutine(setPlayerMood(string sMood, string sPlayer);

// routine in SceneController
non-public IEnumerator setPlayerMood(string sMood, string sPlayer)
    {
        Animator animator;

        if( sPlayer == "Player1")
            animator = Player1.GetComponent();
        else
            animator = Player2.GetComponent();

        swap (sMood)
        {
            case "indignant":
                animator.GetComponent().indignant = true;                
                break;

            case "disgust":
                animator.GetComponent().disgust = true;
                break;

            case "unhappy":
                animator.GetComponent().unhappy = true;
                break;

            case "completely satisfied":
                animator.GetComponent().completely satisfied = true;
                break;

            case "numb":
                animator.GetComponent().numb = true;
                break;

            case "amazed":
                animator.GetComponent().amazed = true;
                break;
        }

        yield return null;
    }

// Playanimation class
public class Playanimation : MonoBehaviour
    {
        public string anim;
        public bool delayed;
        public bool completely satisfied;
        public bool unhappy;
        public bool indignant;
        public bool amazed;
        public bool disgust;
        public bool numb;


        void Begin()
        {
            GetComponent().Play(anim);
            if (delayed)
            {
                StartCoroutine("playanim", anim);
            }

            if (completely satisfied) GetComponent().SetLayerWeight(1, 1f);
            else if (unhappy) GetComponent().SetLayerWeight(2, 1f);
            else if (indignant) GetComponent().SetLayerWeight(3, 1f);
            else if (amazed) GetComponent().SetLayerWeight(4, 1f);
            else if (disgust) GetComponent().SetLayerWeight(5, 1f);
            else if (numb) GetComponent().SetLayerWeight(6, 1f);
        }

        IEnumerator playanim(string anim)
        {
            GetComponent().pace = 0.65f;
            yield return new WaitForSeconds(Random.Vary(0f, 2f));
            GetComponent().pace = 1f;
            GetComponent().Play(anim);
        }

        public void playtheanimation(string newanim)
        {
            anim = newanim;
            StartCoroutine("playanim", anim);
        }
    }
}

Any assistance is appreciated.

Related Articles

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Latest Articles