I thought I had an idea of what I was doing, but I obviously don’t. I am trying to get some monsters (Clizy) to instantiate in around the map, I just need them not to appear in the center. I also need them to randomly instantiate (but not in the middle) I worked except when both else statements were true. I know this probably won’t make any sense, but if someone can point out my error, or another way to do this I would be very thankful.
my error is this: .js(25,131): BCE0044: expecting ), found ‘Quaternion’.
function DecideXaxis (X : int, XVal : int){
if(X <=1){
XVal = Random.Range(-9, 15);
} else if (X <= 2){
XVal = Random.Range(-9, 90);
}else XVal = Random.Range(75, 90);
return XVal;
}
function DecideZaxis (Z : int, ZVal : int){
if(Z <=1){
ZVal = Random.Range(-9, 15);
} else if (Z <= 2){
ZVal = Random.Range(-9, 90);
}else ZVal = Random.Range(75, 90);
return ZVal;
}
var Clizy : GameObject;
var lightObject : Light;
function OnTriggerStay (other : Collider) {
if(lightObject.enabled == true){
if (other.CompareTag ("Respawn")) {
Destroy (other.gameObject);
yield WaitForSeconds (1);
do {
Instantiate (Clizy, Vector3(DecideXaxis(Random.Range(1,3), 0),-16,DecideZaxis(Random.Range(1,3))) Quaternion.identity);
} while(Z > 2 && X > 2) {
Instantiate (Clizy, Vector3(DecideXaxis(Random.Range(1,3), 0),-16,DecideZaxis(Random.Range(1,3))) Quaternion.identity);
}
}
}
}
I believe you’re missing a comma following the position and before the quaternion;
what you have is
Instantiate (Clizy, Vector3(DecideXaxis(Random.Range(1,3), 0),-16,DecideZaxis(Random.Range(1,3))) Quaternion.identity);
when you’re after
Instantiate (Clizy, Vector3(DecideXaxis(Random.Range(1,3), 0),-16,DecideZaxis(Random.Range(1,3))), Quaternion.identity);
Because there’s no comma, it’s giving you the error because it’s assuming that’s the end of the parameters you’re passing in (position/rotation are optional in Instantiate()).
The format for do/while is
do {
// something
}
while (condition);
You appear to be trying to combine a standard while loop with a do/while loop, which isn’t possible. However that would be an infinite loop anyway, since you never change Z or X inside the loop.
thanks guys you were a great help, not that anyone will need to use this but the finished code looks like this:
function DecideXaxis (X : int, XVal : int){
if(X <=1){
XVal = Random.Range(-9, 90);
}else if (X <= 2){
XVal = -10;
}else if (X <= 3) {
XVal = Random.Range(-9, 90);
}else if (X <= 4){
XVal = 80;
}
return XVal;
}
function DecideZaxis (Z : int, ZVal : int){
if(Z <=1){
ZVal = 60;
}else if (Z <= 2){
ZVal = Random.Range(-35, 65);
}else if (ZVal <= 3) {
ZVal = -30;
}else if (Z <= 4){
ZVal = Random.Range(-35, 65);
}
return ZVal;
}
var Clizy : GameObject; // monster prefab
var lightObject : Light; //light that activates the forcefeild
function OnTriggerStay (other : Collider) {
if(lightObject.enabled == true){ // if the light is on
if (other.CompareTag ("Respawn")) {
Destroy (other.gameObject); // destroy it
yield WaitForSeconds (1.5);
var number : int;
number = Random.Range(1,4);
Instantiate (Clizy, Vector3(DecideXaxis(number, 0),-16,DecideZaxis(number, 0)), Quaternion.identity);
}
}
}
so if anyone is looking on this post looking for the actual answer to this question, it is here, but I couldn’t have done it without you guys!! I was doing it all wrong anyway