Hi guys!
Happy new year! I have solved the challenge in this lecture this way and wanted to ask if it is also viable? (I got rid of all my red lines. So it should…)
public class EnemyPathing : MonoBehaviour
{
WaveConfig waveConfig;
List<Transform> waypoints;
float moveSpeed;
int waypointIndex = 0;
// Start is called before the first frame update
void Start()
{
waypoints = waveConfig.GetWaypoints();
moveSpeed = waveConfig.GetMoveSpeed();
transform.position = waypoints[waypointIndex].transform.position;
}
// Update is called once per frame
void Update()
{
Move();
}
private void Move()
{
if (waypointIndex <= waypoints.Count - 1)
{
var targetPosition = waypoints[waypointIndex].transform.position;
var movementThisFrame = moveSpeed * Time.deltaTime;
transform.position = Vector2.MoveTowards(transform.position, targetPosition, movementThisFrame);
if (transform.position == targetPosition)
{
waypointIndex++;
}
}
else
{
Destroy(gameObject);
}
}
}