Search Unity

Pls Help Me :(

Discussion in 'Scripting' started by XRifkyProX, Jul 12, 2018.

  1. XRifkyProX

    XRifkyProX

    Joined:
    Jul 12, 2018
    Posts:
    3
    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. [RequireComponent(typeof(PlayerMotor))]
    5. public class PlayerController : MonoBehaviour {
    6.  
    7.     [SerializeField]
    8.     private float speed = 5f;
    9.  
    10.     private PlayerMotor motor;
    11.  
    12.     void start ()
    13.     {
    14.         motor = GetComponent<PlayerMotor>();
    15.     }
    16.  
    17.     void Update ()
    18.     {
    19.         /*Calculate movement velocity as a 3D vector*/
    20.         float _xMov = Input.GetAxisRaw("Horizontal");
    21.         float _zMov = Input.GetAxisRaw("Vertical");
    22.  
    23.         Vector3 _movHorizontal = transform.right * _xMov;
    24.         Vector3 _movVertical = transform.forward * _zMov;
    25.  
    26.         /*Final movement vector*/
    27.         Vector3 _velocity = (_movHorizontal + _movVertical).normalized * speed;
    28.  
    29.         /*Apply movement*/
    30.         motor.Move(_velocity);
    31.     }
    32. }
    33.  
    The error Says : NullReferenceException: Object reference not set to an instance of an object
    PlayerController.Update () (at Assets/PlayerController.cs:29)
     
  2. XRifkyProX

    XRifkyProX

    Joined:
    Jul 12, 2018
    Posts:
    3
    Pls Help ME :(
     
  3. Kiwasi

    Kiwasi

    Joined:
    Dec 5, 2013
    Posts:
    16,860
    Try replacing start with Start. The compiler cares a lot about capital letters in the right place.
     
    jrz371 likes this.