public void Spawn() { if (isSpawned == false) { Vector3 destinationDirection = nextWaypoint.transform.position - transform.position; spawnedObject = Instantiate(prefab, transform.position, Quaternion.LookRotation(destinationDirection)); isSpawned = true; spawnedTransform = spawnedObject.GetComponent <Transform>(); CarMovement carMovement = spawnedObject.GetComponent <CarMovement>(); carMovement.CurrentWaypoint(nextWaypoint); } }