I'm not getting the first animation wheel of my game

2

Good afternoon, I'm having a hard time understanding what this error is, I still have only a few days in the programming world. Someone can help me.

using UnityEngine;
using System.Collections;

public class Player : MonoBehaviour {
    public float Velocidade;
    public Transform player;
    private Animator animator;



    // Use this for initialization
    void Start () {
        animator = player.GetComponent<Animator>();
    }

    // Update is called once per frame
    void Update () {
        Movimentar();
    }
    void Movimentar ()
    {
        animator.SetFloat ("Run", Mathf.Abs (Input.GetAxis ("Horizontal")));

    if (Input.GetAxisRaw ("Horizontal") > 0) {
            transform.Translate (Vector2.right * Velocidade * Time.deltaTime);
            transform.eulerAngles = new Vector2 (0,0);
        }

            if(Input.GetAxisRaw ("Horizontal") < 0) {

            transform.Translate(Vector2.right * Velocidade * Time.deltaTime);
                transform.eulerAngles = new Vector2(0,180);
            }
        }
}

The error after the project runs runs

  

NullReferenceException: Object reference not set to an instance of an   object Player.Move () (at Assets / Scripts / Player.cs: 22)   Player.Update () (at Assets / Scripts / Player.cs: 18)

     

UnassignedReferenceException: The variable player of Player has not   been assigned. You probably need to assign the variable player of the   Player script in the inspector.   UnityEngine.Component.GetComponent [Animator] () (at   C: /buildslave/unity/build/artifacts/generated/common/runtime/UnityEngineComponent.gen.cs:45)   Player.Start () (at Assets / Scripts / Player.cs: 13)

    
asked by anonymous 01.05.2015 / 21:34

2 answers

1

The error is in your project and not in the code.

It's complaining that you did not assign any value to the player variable. Within your project, drag the asset you want to get the animator property up to the player variable.

    
01.05.2015 / 22:19
0

Have you declared the variable Player ? In the first line you could declare as a New Transform . Home In your code it looks like this:

public Transform player;

Replace with this:

public Transform player = new Transform;

I hope it works ... Hugs

    
02.05.2015 / 21:08