I keep getting errors even though I did everything as he did

Updated 6 days ago in [A] Unity Scripting
Share on Facebook0Tweet about this on TwitterShare on Google+0Share on Reddit0
2 on November 24, 2017

So I am new to Unity, I started following Brackeys guide on this one

https://www.youtube.com/watch?v=S2mK6KFdv0I

 

However at 11:15 when we were going to walk the character I tabbed back into Unity after finishing the script.

(I’ve rewatched the first 11 minutes about 6 times now) to make sure everything is correct.

I keep getting these errors

https://i.imgur.com/lzzjabw.gifv

 

Here is my PlayerController script

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
[RequireComponent(typeof(PlayerMotor))]
public class PlayerController : MonoBehaviour
{
    public LayerMask movementMask;
    Camera cam;
    PlayerMotor motor;
    // Use this for initialization
    void Start()
    {
        cam = Camera.main;
        motor.GetComponent<PlayerMotor>();
    }
    // Update is called once per frame
    void Update()
    {
        if (Input.GetMouseButtonDown(0))
        {
            Ray ray = cam.ScreenPointToRay(Input.mousePosition);
            RaycastHit hit;
            if (Physics.Raycast(ray, out hit, 100, movementMask))
            {
                motor.MoveToPoint(hit.point);
                //Stop focusing any objects
            }
        }
    }
}

 

And here is the PlayerMotor

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.AI;
[RequireComponent(typeof(NavMeshAgent))]
public class PlayerMotor : MonoBehaviour
{
    NavMeshAgent agent;
    // Use this for initialization
    void Start()
    {
        agent.GetComponent<NavMeshAgent>();
    }
    public void MoveToPoint(Vector3 point)
    {
        agent.SetDestination(point);
    }
}
  • Liked by
Reply
0 on November 24, 2017

It says it’s null… Make sure the you have the playercontroller and playermotor on the gameobject.

  • Liked by
Reply
Cancel

Bro, you have give “.” instead of ” = ” in the PlayerMotor script in the Start() function and in the Start() function of the PlayerController Script

  • Liked by
Reply
Cancel