spawn point problem

hi guys i really needed a help for spawn point script. its not working. i want the function to be like when my player collide with the object. the object will then respawn multiply to a spawn point in vertical position.

and here my spawnpoint script:

var timer : float = 0.0;

  var spawning : boolean = false;

  var prefab : Rigidbody;

  var spawn1 : Transform;

  var spawn2 : Transform;

  var spawn3 : Transform;

  

  function Update () {

   //check if spawning at the moment, if not add to timer

   if(!spawning){

  timer += Time.deltaTime;
  
 

   }

   //when timer reaches 2 seconds, call Spawn function

 
    Spawn();

//return;
}

  function Spawn(){

   //set spawning to true, to stop timer counting in the Update function

   spawning = true;

   //reset the timer to 0 so process can start over

   timer = 0;

   

   //select a random number, inside a maths function absolute command to ensure it is a whole number

   var randomPick : int = Mathf.Abs(Random.Range(1,4));

   

   //create a location 'Transform' type variable to store one of 3 possible locations declared at top of script

   var location : Transform;

   

   //check what randomPick is, and select one of the 3 locations, based on that number

   if(randomPick == 1){

    location = spawn1;

    Debug.Log("Chose pos 1");

   }

   else if(randomPick == 2){

    location = spawn2;

    Debug.Log("Chose pos 2");

   }

   else if(randomPick == 3){

    location = spawn3;

    Debug.Log("Chose pos 3");

   }

   

   //create the object at point of the location variable

   var thingToMake : Rigidbody = Instantiate(prefab, location.position, location.rotation);

    thingToMake.AddForce(Vector3(0,0,100));

   

   //halt script for 1 second before returning to the start of the process

   yield WaitForSeconds(1);

   //set spawning back to false so timer may start again

   spawning = false;

  }

"its not working." Isn't descriptive enough for a good response, are you getting errors? What is happening that you want to happen? What is happening that you don't want to happen?

1 Answer

1

I used this for my game to spawn my player from one spot to another take it manipulate it a lil to ur game and it should work just fine.

var timeToPort : float = 2.0;

var tubePortalTo : Transform;

var soundTube : AudioClip;

private var moveDown : boolean = false;

private var moveUp : boolean = false;

function OnTriggerStay (other : Collider)
{
if (other.tag == “Player”)
{
if (Input.GetAxis (“Vertical”) <0 )
{
var velX = other.GetComponent (playerControls).velocity.x;
var moveDir = other.GetComponent (playerControls).moveDirection;

		if (moveDir == 0)
		{
			velX = 0;
			other.GetComponent (aniSprite).aniSprite (16, 16, 0, 9, 16, 24);
		}
		if (moveDir == 1)
		{
			velX = 0;
			other.GetComponent (aniSprite).aniSprite (16, 16, 0, 8, 16, 24);
		}	
		other.GetComponent (playerControls).enabled = false;
		moveDown = true;
		if (moveDown)
		{
			other.transform.Translate (0, -5 * Time.deltaTime, 0);
			other.GetComponent (playerControls).PlaySound (soundTube, 0);
			yield WaitForSeconds (.2);
			other.renderer.enabled = false;
			yield WaitForSeconds (timeToPort);
			other.transform.position = tubePortalTo.transform.position;
			moveDown = false;
			moveUp 	   = true;
		}
		if (moveUp)
		{
			yield WaitForSeconds (1);
			other.GetComponent (playerControls).PlaySound (soundTube, 0);
			other.GetComponent (playerControls).gravity = 0.0;
			other.renderer.enabled = true;
			other.transform.Translate ( 0, 4 * Time.deltaTime, 0);
			yield WaitForSeconds (.3);
			other.GetComponent (playerControls).gravity = 20.0;
			other.GetComponent (playerControls).enabled = true;
			moveUp = false;
		}
	}
}

}