- Home /
Car Script Help
I made a script to make a car go back and forth between two points forever in a loop. For some reason it just skips to the second point and stays there
using UnityEngine; using System.Collections; public class VehicleController : MonoBehaviour { public Transform destination; public Transform destination2; private UnityEngine.AI.NavMeshAgent agent; void Start () { agent = gameObject.GetComponent<UnityEngine.AI.NavMeshAgent>(); Begin(); //runs Begin } private void Begin () { agent.SetDestination(destination.position); //tells the car to go to destination if (agent.remainingDistance < 1f) //when the car gets close, run NextDestination1 { NextDestination1(); } } private void NextDestination1 () { agent.SetDestination(destination2.position); //tells the car to do to destination2 if (agent.remainingDistance < 1f) //when the car gets close, run Begin { Begin(); } } }