- Home /
I'm having problems with my code
I created 4 empty objects around the board one on each corner. Each corner has a tag and name "yoWassup1"- up to "yoWassup4". I want a timer to count up until it gets to 5 and then picks a random number and spawns at the corresponding spawn point. The idea is for it to go in a loop and every 5 seconds the game gets harder and new ball is spawned in.
The error that comes up is that "The associated script can not be loaded. Please fix any compile errors." no errors show up on the console. It just doesn't go into play mode.
thanks a lot
my code is as follows:
var thePrefab : GameObject;
public var myTimer : float = 0.0;
var spawning : boolean = false;
var yoWassup1 : Transform;
var yoWassup2 : Transform;
var yoWassup3 : Transform;
var yoWassup4 : Transform;
function Update () {
if(!spawning){
myTimer += Time.deltaTime;
}
if(myTimer >= 5)
{
Spawn()
}
}
function Spawn(){
spawning = true;
myTimer=0;
var randNumber: int =(Random.Range(1,5));
var location :Transform;
if (randNumber == 1){
location = yowassup1;
Debug.Log ("PICKED 1");
}
else if (randNumber == 2){
location = yowassup2;
Debug.Log ("PICKED 2");
}
else if (randNumber == 3){
location = yowassup3;
Debug.Log ("PICKED 3");
}
else if (randNumber == 4){
location = yowassup4;
Debug.Log ("PICKED 4");
}
Instantiate(thePrefab, location.position, location.rotation);
spawning = false;
}
Have you linked gameobjects in the editor to deter$$anonymous$$e the spawn points?
Answer by robertbu · Dec 08, 2013 at 08:35 PM
Any chance you have error reporting turned off in the Console window. The stop sign with the '!' needs to be selected in the upper right corner of the Console window. I find five errors in this script. Your are missing ';' at the end of line 27, and the variable names you use don't match your declaration:
'yowasup1' is not the same as 'yoWassup1'. Case must match.
Your answer
![](https://koobas.hobune.stream/wayback/20220613123726im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
How do I control where enemies spawn? 1 Answer
Prevent object from spawning at a spawn point twice in a row? 3 Answers
Network.Instantiate players at each spawnpoint? Don't use the same spawnpoint? 1 Answer
Storing the Position Generated by Random.Range 2 Answers
one scene multiple spawn points 1 Answer