I can't change the target of NavMeshAgent
I developp a car game and I need a target for the AI but I want they (the cars) deplace aleatory (ther is 3 differents possibilites but never choose someone) this is my code (all of my AI) : using System.Collections; using System.Collections.Generic; using UnityEngine.AI; using UnityEngine;
public class iaCarController : MonoBehaviour { //autres gameObject public Transform Target; //Definition de l'agent de n²avigation public UnityEngine.AI.NavMeshAgent agent; //direction a prendre public int direction = 1; //distance de Target public float distance; //script triggerCarrefour public triggerCarrefour triggerCarrefour; //DIfférentes targets public Transform Target0; public Transform Target1; public Transform Target2; public Transform Target3;
void Start()
{
agent = gameObject.GetComponent<UnityEngine.AI.NavMeshAgent>();
Target = GameObject.Find("Target").transform;
Debug.Log("Debut de programme");
}
void Update()
{
Target0 = GameObject.Find("Target0").transform;
Target1 = GameObject.Find("Target1").transform;
Target2 = GameObject.Find("Target2").transform;
Target3 = GameObject.Find("Target3").transform;
distance = Vector3.Distance(transform.position, Target.position);
direction = triggerCarrefour.sortieSelect;
if(direction == 1)
{
agent.destination = Target0.position;
Debug.Log("Target=Target0");
}
if (direction == 2)
{
agent.destination = Target1.position;
}
if (direction == 3)
{
agent.destination = Target2.position;
}
if (direction == 4)
{
agent.destination = Target3.position;
}
}
}
PS : I'm frensh, the comments are in frensh if you don't understand you can say me