Hello i need help. I need to assign my both players (P1, P2) to an array. But then i did a quick google search i found out that using a List is a better option. Here is my script, i got no errors but it does not find P1 or P2 but their names are “P1” and “P2” Can someone help me? thanks
using System.Collections;
using UnityEngine.AI;
using System.Collections.Generic;
using UnityEngine;
public class SetDestinaiton : MonoBehaviour {
public List<Transform> players = new List<Transform> ();
Transform dest;
void Start ()
{
players.Add (GameObject.Find ("P1").transform);
players.Add (GameObject.Find ("P2").transform);
dest = players [Random.Range (0, players.Count)];
}
void Update ()
{
GetComponent<NavMeshAgent> ().destination = dest.transform.position;
}
}