Ask coding questions

← Back to all posts
Unity help
Bunnytoes (111)

My unity code doesn't work. It says fix compiler errors before running. I have this is so far
enemy movement

using UnityEngine;

public class Enemy : MonoBehaviour {

	public float speed = 10f;

	private Transform target;
	private int wavepointIndex = 0;

	void Start ()
	{
		target = Waypoints.points[0];
	}

	void Update ()
	{
		Vector3 dir = target.position - transform.position;
		transform.Translate(dir.normalized * speed * Time.deltaTime, Space.World);

		if (Vector3.Distance(transform.position, target.position) <= 0.4f)
		{
			GetNextWaypoint();
		}
	}

	void GetNextWaypoint()
	{
		if (wavepointIndex >= Waypoints.points.Length - 1)
		{
			Destroy(gameObject);
			return;
		}

		wavepointIndex++;
		target = Waypoints.points[wavepointIndex];
	}

}

and waypoints

using UnityEngine;

public class Waypoints : MonoBehaviour
{
    public static Transform[] points;


    void Awake ()
    {
        points = new Transform[transform.childCount];
        for (int i = 0; i < points.Length; i++)
        {
           points[i] = transform.GetChild(i);
        }
    }
}

why won't it work
please help

Answered by SixBeeps (5231) [earned 5 cycles]
View Answer
Comments
hotnewtop
SixBeeps (5231)

Please send screenshots of the error console.

Bunnytoes (111)

@SixBeeps here it is

it says all compiler errors must be fixed before entering playmode

SixBeeps (5231)

@Bunnytoes That's not the error console. To open the error console, go here:

A window titled 'Console' should appear. Those will be where your errors show up.

Bunnytoes (111)

@SixBeeps thanks but I just know why it isn't working. that's all I need to know

SixBeeps (5231)

@Bunnytoes That's what the console is for. It tells you what's wrong.