My switch statement wont work

Hello,

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!

Your switch is very wrong. switch statements need something to switch on and define a block. They follow the form:

 switch(someIntegerValue) {
      case integerResult : {
          //do something
          break;
      }
      case anotherIntegerResult : {
          //do something
          break;
      }
      //...
      default : {
          //do something
      }
 }

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:

if(someIntegerValue == integerResult) {//case integerResult
    //do something
} else if( someIntegerValue == anotherIntegerResult) {//case anotherIntegerResult
    //do something
} else if(...) {//...
} else { //default
    //do something
}

In your case, you could do something more intuitive that wouldn't require a switch like so:

var respawnPoints : Transform[];
var currentRespawnPoint : int = 0;

function Update() {
    if(respawnPoints.Length != 0 && transform.position.y <-30) {
        currentRespawnPoint = Mathf.Clamp(currentRespawnPoint, 0,
                                          respawnPoints.Length -1);
        transform.position = respawnPoints[currentRespawnPoint].position;
    }
}

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.