Coding Fora logo
  • main_navigation_menu_icon.png
  • Search
  • ic_more_vert.png

UnassignedReferenceException: The variable player of CharControl has not be...

You are here
Fora > UnassignedReferenceException: The variable player of CharControl has not be...

1_180303121314.jpg
Europa

vote_up

0

vote_down

Posted by Europa · 24 May 2019 (93 days ago) · Report · Email

Error:
UnassignedReferenceException: The variable player of CharControl has not been assigned.You probably need to assign the player variable of the CharControl script in the inspector.UnityEngine.GameObject.GetComponent[T] () (at C:/buildslave/unity/build/Runtime/Export/Scripting/GameObject.bindings.cs:28)CharControl.Update () (at Assets/Scripts/Characters/CharControl.cs:38)

 

Script:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class CharControl : MonoBehaviour
{
    // Variables
    public GameObject player;
    public bool isRunning;
    public float yMove; // Horizontal Rotation
    public float zMove; // Vertical Foward and backward


    // Start is called before the first frame update
    void Start()
    {
        
    }

    // Update is called once per frame
    void Update()
    {
        // Moving horizontal or vertical
        if(Input.GetButton("Horizontal") || Input.GetButton("Vertical"))
        {
            player.GetComponent<Animation>().Play("Run"); // Run animation
            yMove = Input.GetAxis("Horizontal") * Time.deltaTime * 150; // Move character relative to the world around (150=speed)
            zMove = Input.GetAxis("Vertical") * Time.deltaTime * 8; // Move speed = 8
            isRunning = true;

            transform.Rotate(0, yMove, 0);
            transform.Translate(0, 0, zMove);


        } // Horizontal, vertical
        else
        {
            player.GetComponent<Animation>().Play("Idle"); // Stand still
            isRunning = false;
        }
    } // Update
}

Reply

Social Media

youtube.png