- Home /
Waypoints using a Switch...
I got script that chooses a new way-point when its triggered. It currently works but the clones that are spawning instantiate with another clones way-point and not the default way-point 0. How can I make each clone not effect each other?
private var waypoint = 0;
function OnTriggerEnter (other : Collider) {
if (other.CompareTag("WayPointCube")){
spot = Random.Range(0,2);
Debug.Log("Hit");
switch(spot){
case 1:
waypoint = 2;
break;
case 2:
waypoint = 1;
break;
case 0:
waypoint = 0;
break;
}
}
You will need to show how do you create your "WaypointCube", I mean, the script attached to the prefab, as well as how you handle the waypoint data structure.
But without knowing that maybe you could store your waypoints outside the WaypointCubes and set it´s destination point as the next waypoint from your new global waypoint list/stack at the moment right after their instantiation. Then, when you reach that WaypointCube´s destination point, you repeat the proccess...
I have this script as apart of an AI script, When the AI collides with an object with the tag "WayPointCube" the script is triggered. The way-points are in an Array. The variable "waypoint" is the number that is used to reference the transform within the array.
var target : Transform[];
var dir = (target[waypoint].position - transform.position).normalized;
How are you instantiating your clones? You should be using a prefab, not copying existing ones (unless there's a good reason to do it that way, which there sometimes is)
Answer by cj_coimbra · Nov 03, 2011 at 08:57 PM
Try setting the line "private var waypoint = 0;" inside the Awake function of the script attached to the clone prefab.
No dice. Would disabling the function after it chooses a way point work?
Answer by roamcel · Nov 05, 2011 at 05:40 AM
Quite certainly, what happens is that somehow all instances are 'sharing' the waypoint structure.
Since I guess you're using a script that's attached to a gameobject in the scene, and you somehow use that gameobject for all your instances... well, since there's -one- instance, there can be only -one- waypoints list!
The answer to your question is: create a "prefab out of the waypoints" and pass it as a "parameter" to your gameobjects after creation.
Your answer
Follow this Question
Related Questions
Colliders and waypoints... 2 Answers
Switching between controllers - why do I have to press spacebar twice before it works? 1 Answer
The name 'Joystick' does not denote a valid type ('not found') 2 Answers
Question on Vector3.Reflect() 2 Answers
What is the best way to script third person real-time action melee combat in C#? 1 Answer