I’m following this tutorial (noobtuts - Unity 2D Pac-Man Tutorial) and I seem to be doing something wrong. Near the bottom of the tutorial, there is a script that tells the ghosts to move, however when I implement it in my game the ghost will only go to the first waypoint I created and not the others. All of the waypoints are properly associated with the script after it has been placed on the ghost. Can anybody think of anything else I could be doing wrong, or something I’ve missed? I’ve copied the code exactly like this:
using UnityEngine;
using System.Collections;
public class GhostMove : MonoBehaviour
{
public Transform waypoints;
int cur = 0;
public float speed = 0.3f;
void FixedUpdate()
{
// Waypoint not reached yet? then move closer
if (transform.position != waypoints[cur].position)
{
Vector2 p = Vector2.MoveTowards(transform.position,
waypoints[cur].position,
speed);
GetComponent<Rigidbody2D>().MovePosition(p);
}
// Waypoint reached, select next one
else cur = (cur + 1) % waypoints.Length;
// Animation
Vector2 dir = waypoints[cur].position - transform.position;
GetComponent<Animator>().SetFloat("DirX", dir.x);
GetComponent<Animator>().SetFloat("DirY", dir.y);
}
void OnTriggerEnter2D(Collider2D co)
{
if (co.name == "pacman")
Destroy(co.gameObject);
}
}