- Home /
 
Vector3 randomize spawnpoints
Okay, so I'm trying to make a multiplayer game with randomized spawnpoints. maybe spawnpoint; A: 0,0,0 B: 10,2,4 C: 9,2,8 etc.
Now if I make an array how do I randomize 1 position from our positions[3]; Randomrange doesn't work for me or I'm doing it wrong. Here's a bit of sample code:
 var positions : Vector3[];
 var Health = 100;
 var Deaths = 0;
 var isDead : boolean = false;
 
  function Playerdeath()
  {
 Respawn();
  Health = 100;
 Deaths +=1;
 isDead = false; 
  }
  
  function Respawn()
  {
  var ResPos : Vector3 = positions[Random.Range(0,   positions.length)];
 
               transform.position = Vector3 (ResPos); }//move the player on death to new position with full health again add 1 to death count
so any suggestions?
Answer by giulio-pierucci · Feb 09, 2015 at 08:53 PM
Seems correct. Do you have set position array?
EDIT:
I try the code and is fully functional, except for last row, i get build error. This is correct:
 var positions : Vector3[];
 var Health = 100;
 var Deaths = 0;
 var isDead : boolean = false;
  
 function Start()
 {
     Respawn();
     Health = 100;
     Deaths +=1;
     isDead = false; 
 }
   
 function Respawn()
 {
     var ResPos : Vector3 = positions[Random.Range(0,   positions.length)];
     transform.position = ResPos; 
 }
 
               P.S.: I used method Start() for my convenience
Your answer
 
             Follow this Question
Related Questions
[Solved] Help with my music manager 1 Answer
JS: Access sections of an array, without activating the rest 2 Answers
Add Force At Player 0 Answers
Problem with gameObject Array 1 Answer
Assigning Player Numbers 0 Answers