- Home /
 
the script runs when it was first created, but if I close my unity and re-run the game the script says nul reference ?! Why is it like that? please help
using System.Collections; using System.Collections.Generic; using UnityEngine;
[RequireComponent(typeof(MoveController))] public class Player : MonoBehaviour {
 [SerializeField] float _speed;
 [SerializeField] MouseControl mouseControl;
 private InputController inputController;
 private Vector2 mouseInput;
 // MoveController
 private MoveController m_moveController;
 private MoveController moveController
 {
     get
     {
         if (m_moveController == null)
         {
             m_moveController = GetComponent<MoveController>();
         }
         return m_moveController;
     }
 }
 [System.Serializable]
 public class MouseControl
 {
     public Vector2 _damping;
     public Vector2 _sensitifity;
 }
 private void Awake()
 {
     inputController = GameManager.Instance.InputController;
     GameManager.Instance.localPlayer = this;
 }
 private void Update()
 {
     Vector2 _direction = new Vector2(inputController.Horizontal * _speed, inputController.Vertical * _speed);
     moveController.Move(_direction);
     mouseInput.x = Mathf.Lerp(mouseInput.x, inputController.MouseInput.x, 1f / mouseControl._damping.x);
     transform.Rotate(Vector3.up * mouseInput.x * mouseControl._sensitifity.x);
 }
 
               }
               Comment
              
 
               
              better show us Game$$anonymous$$anager.Instance.InputController also.
Your answer
 
             Follow this Question
Related Questions
Delegates versus class references 1 Answer
Event to change level 1 Answer
Login form: Do I have to set custom delegates to null in OnDestroy? 0 Answers