I looked around the web and I couldn't find this exact problem so I'm going to go ahead post the questions and hope someone has an answer for it.
This is my problem I have a prefab of an AI character,the prefab has code attached to it for pathfinding as well as basic character control. I can get the character to go between two predefined waypoints. The problem runs into when I try and make random waypoints for it to go to. let's say I have eight waypoints and I wanted the AI to go to four of them and I want those four to be chosen randomly. the code I wrote for this works perfectly fine if the object is already in the game prior to runtime. But if I make a prefab of this object unity crashes the moment I click run. I took out the random waypoint script and tried running it again, it worked perfectly fine for all predefined waypoints but the moment I wanted to choose one randomly the unity freezes. I don't have an error message to show you guys because it freezes before can make an error message. No show you the script that's causing the game to freeze and I love to know if you guys have any alternative ideas or ways of fixing this problem.
waypointLength = waypointAll.Length;
for(int loopnum = 0; loopnum < CreatAI.HowManyWaypoints; loopnum++){ //this is for how many waypoints will be created
Loopstart:
num = Random.Range(0,waypointLength); //creates a random number between zero and how many waypoints there are
for (int waypointTest = 0; waypointTest < CreatAI.HowManyWaypoints; waypointTest++){ //this is the integer for the waypoint test loop
if (Waypoint[waypointTest] == waypointAll[num]){
goto Loopstart; //if it fails then the two waypoints are the same if so go to loopstart and redo the test
}
}
ObjectNumber[loopnum] = num; //makes the object number the same as the waypoint that way if the 3rd stop is going to object 7 the AI knows that
Waypoint[loopnum] = waypointAll[num]; //copies the waypoint information of the random waypoint to the new waypoint array, putting them in order
}
waypointall[] is where the eight waypoints are stored. Waypoint[] is where the four randomly chosen ones are stored. If I take this part of the script out unity3D doesn't freeze but my AI doesn't go to the waypoints randomly like I needed to.
I've tried creating this script four different ways applying it to the prefab, I've even tried applying it to a global variable that the prefab accesses and the moment the prefab axes that global variable it freezes. I even had it where the prefab accesses a global variable that has already randomly chosen those four waypoints prior to the creation of the prefab. every way I've tried it freezes a moment that it tries to access these waypoints.