I am quiet new to the hole game makeing here and i suck at it, so please be nice to me thanks.
Well i am trying to make a respawn script and in that script i want to have my player spawn at diffrent locations randomly. I have made a respawn script like this:
var RespawnPoint : Transform;
function Update () {
if(gameObject.transform.position.y <-30)
gameObject.transform.position = RespawnPoint.transform.position;
}
But when a add a "switch" to it like:
var RespawnPoint : Transform;
var RespawnPoint2 : Transform;
function Update () {
switch
case 1 :
(gameObject.transform.position.y <-30)
gameObject.transform.position = RespawnPoint.transform.position;
break;
case 2 :
(gameObject.transform.position.y <-30)
gameObject.transform.position = RespawnPoint2.transform.position;
break;
It says "Expecting (, found "case" And when i do that wven though it dose not look right in my eyes. Unity just dishes up more errors. Is there anyway to fix this? As i said before i am not very good at this. So if i am makeing a mistake somewhere in the script please tell me and please be nice. Thanks!
Integer values acceptable for mono's switch statement would include int, bool, string, enum, and byte (and I think float as well although I've never seen a reason to use them there).
switch statements are best used to replace blocks of:
You have a switch statement but you are not switching on anything. You need some variable passed to the switch for it to define cases.
Add this to your code:
var respawnMode : int = 1;
switch(respawnMode)
{
case 1:
//first case code
break;
case 2:
//second case code
break;
}
Then its simply a matter of changing respawn mode to 1 or 2 or whatever you like. If you only ever have 2 respawn points to switch between you might want to use a boolean instead (true/false) or have a default case that redirects to another respawn point.