NullReferenceException: Object reference not set to an instance of an object
EnemyPathing.Move () (at Assets/Scripts/EnemyPathing.cs:31)
EnemyPathing.Update () (at Assets/Scripts/EnemyPathing.cs:21)
In Console, I got these Bug even they are the same with Rick on Github: https://github.com/CompleteUnityDeveloper/06-Laser-Defender/blob/master/Laser%20Defender/Assets/Scripts/EnemyPathing.cs
My script here, thanks you ^o^
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class EnemyPathing : MonoBehaviour
{
WayConfigScripableObj pathData;
List<Transform> wayPoints;
int waypointIndex = 0;
// Start is called before the first frame update
void Start()
{
wayPoints = pathData.GetPathData();
transform.position = wayPoints[waypointIndex].transform.position;
}
// Update is called once per frame
void Update()
{
Move();
}
public void GetPathData(WayConfigScripableObj pathData)
{
this.pathData = pathData;
}
private void Move()
{
if (waypointIndex <= wayPoints.Count - 1)
{
var targetPos = wayPoints[waypointIndex].transform.position;
var enemySpeedDelta = pathData.GetSpeedOfEnemy() * Time.deltaTime;
transform.position = Vector2.MoveTowards
(transform.position, targetPos, enemySpeedDelta);
if (transform.position == targetPos)
{
waypointIndex++;
}
}
else
{
Destroy(gameObject);
}
}
}