I am new to this whole programming thing, so it mitght be a simple thing but i dont know what.
I am trying to move Object from a Waypoint-Object to another and from there to the next one and so on. My Problem is, that the script cant find my WayPoint-GameObjects with GameObject.Find(name); It just puts an empty Vector into my array.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class AttackBehavior : MonoBehaviour
{
private Vector2[] targets;
private int j = 0;
public void Start()
{
GameObject[] wpObj = GameObject.FindGameObjectsWithTag("WayPointTAG");
Vector2[] goals = new Vector2[wpObj.Length];
goals[0] = GameObject.Find("WayPoint").transform.position;
for (int i = 1; i == wpObj.Length; i++)
{
goals[i] = GameObject.Find("WayPoint (" + i + ")").transform.position;
}
targets = goals;
}
void Update()
{
if(Vector2.Distance(transform.position, targets[j]) == 0)
{
j++;
}
else
{
transform.position = Vector2.MoveTowards(transform.position, targets[j], 5 * Time.deltaTime);
}
}
}