0
\$\begingroup\$

I have a tags script:

public class Tags {
    //Tags
    public static string PLAYER_TAG = "Player";
    public static string PLATFORM_TAG = "Platform";

    //Player Animation Tags
    public static string ANIMATION_IDLE = "idle";
    public static string WALK = "walk";
    public static string ANIMATION_RUN = "run";
    public static string ANIMATION_JUMP = "jump";
    public static string ANIMATION_JUMP_FALL = "jumpFall";
    public static string ANIMATION_LEDGE_FALL = "ledgeFall";
    public static string ANIMATION_JUMP_LAND = "jumpLand";

}
 Then I have my player animation script:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class PlayerAnimation : MonoBehaviour {

    [SerializeField]
    private Animation anim;

    void Awake () {
        anim = GetComponent<Animation>();
    }

    public void DidJump () {
        anim.Play(Tags.ANIMATION_JUMP);
        anim.PlayQueued(Tags.ANIMATION_JUMP_FALL);
    }

    public void DidLand()
    {
        anim.Stop(Tags.ANIMATION_JUMP_FALL);
        anim.Stop(Tags.ANIMATION_JUMP_LAND);
        anim.Blend(Tags.ANIMATION_JUMP_LAND, 0);
        anim.CrossFade(Tags.ANIMATION_RUN);
    }

    public void PlayerRun()
    {
        anim.Play(Tags.ANIMATION_RUN);
    }
}

When I run the game, the player doesn't run like he's supposed to and I get this error:

NullReferenceException: Object reference not set to an instance of an object
PlayerMovement+<StartGame>c__Iterator0.MoveNext () (at Assets/Scripts/Player Scripts/PlayerMovement.cs:83)
UnityEngine.SetupCoroutine.InvokeMoveNext (IEnumerator enumerator, IntPtr returnValueAddress) (at /Users/builduser/buildslave/unity/build/Runtime/Export/Coroutines.cs:17)

What am I doing wrong here?

\$\endgroup\$
0
\$\begingroup\$

I figured it out. I didn't attach the script to the player.

|improve this answer|||||
\$\endgroup\$

Not the answer you're looking for?Browse other questions tagged or ask your own question.