- Home /
spawning problem
I have a Game object (a cube) that is attached to my player that is a trigger. I have another cube game object that acts as the spawn point, were the enemy will be instantiated. but it is not working please help me out here or point me in the right direction.
below is the script I am using
Thanks.
//Enemy Prefab
var Enemy : GameObject;
//Trigger that is conected to the player that activates this script
var Spawn_Enemys : GameObject;
//gameobjects position for instantiated enemy
var SpawnPosition : Transform;
function OnTriggerEnter (Spawn_Enemys : Collider)
{
//Spawns enemy
Instantiate( Enemy);
//were enemy is instantiated
transform.position = SpawnPosition.transform.position;
}
Answer by Omer · Jun 10, 2011 at 09:48 PM
Delete the last line(transform.position = SpawnPosition.transform.position;) and replace: Instantiate( Enemy); with: Instantiate(Enemy, SpawnPosition.transform.position, SpawnPosition.transform.rotation);
it works I just need to be able to control how many are instantiated.
whats the problem? just do a loop that create as many enemies as you want
var Enemy : GameObject;
var Spawn_Enemys : GameObject;
var SpawnPosition : Transform;
var isCreated: boolean;
function Start ()
{
isCreated = false;
}
function OnTriggerEnter (Spawn_Enemys : Collider)
{
if (isCreated = false)
{
//Spawns enemy
Instantiate(Enemy, SpawnPosition.transform.position, SpawnPosition.transform.rotation);
isCreated = true;
}
}