hi, i’m confused. i’m learning unity from here:
but why when i click the play button, i can’t move my player?
here’s the code:
// script for player
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
[RequireComponent (typeof (PlayerCtrller))]
public class Player_Scrpt : MonoBehaviour {
public float move_speed = 5;
PlayerCtrller controller;
void Start () {
controller = GetComponent<PlayerCtrller>();
}
void Update () {
Vector3 move_input = new Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical"));
Vector3 move_velocity = move_input.normalized * move_speed;
controller.Move(move_velocity);
}
}
// script for player controller
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
[RequireComponent (typeof (Rigidbody))]
public class PlayerCtrller : MonoBehaviour {
Rigidbody my_rbody;
Vector3 velocity;
void Start () {
my_rbody = GetComponent<Rigidbody>();
}
public void Move(Vector3 v)
{
velocity = v;
}
public void FixedUpdate()
{
my_rbody.MovePosition(my_rbody.position + velocity * Time.fixedDeltaTime);
}
}
the error msg says:
NullReferenceException: Object reference not set to an instance of an object Player_Scrpt.Update () (at Assets/Scripts/Player_Scrpt.cs:18) unity
can somebody tell me what’s wrong in my script?