Spawn carachters on locations and destroy the manager after level load

How do I spawn my carachters to the coordinates

473
44
1213

Depending on the class it will spawn another carachter and later on destroy the manager object It’s hard to explain

Sorry for noobish question

//The choose script

#pragma strict

var Spotlight : GameObject;
var isClass1 : boolean = false;
var isClass2 : boolean = false;
var OtherOBJ : GameObject;

function Start () 
{
Spotlight.SetActive(false);
}

function OnMouseEnter () 
{
Spotlight.SetActive(true);
Debug.Log("Entered collider");
}


function OnMouseExit () 
{
Spotlight.SetActive(false);
Debug.Log("Exited collider");
}


function OnMouseUp () 
{
Debug.Log("Clicked box");
Selected();
}

function Selected()
{
if (isClass1 == true)
	{
	 var script: Manager = OtherOBJ.GetComponent(Manager);
      script.spawnClass1 = true;
	}
	if (isClass2 == true)
	{
      script.spawnClass2 = true;
	}
}

//The manager script

#pragma strict

var spawnClass1 : boolean = false;
var spawnClass2 : boolean = false;

var Class1 : GameObject;
var Class2 : GameObject;

function Update()
{
if(spawnClass1 == true)
	{
	Debug.Log("Will Spawn 1");
	LoadLevel();
	}
	if(spawnClass2 == true)
	{
	Debug.Log("Will Spawn 2");
	LoadLevel();
	}
}

function LoadLevel()
{
DontDestroyOnLoad(gameObject);
Application.LoadLevel(2);
Spawn();
}

function Spawn()
{
if(spawnClass1 == true)
	{
	Debug.Log("Spawned 1");
	}
	if(spawnClass2 == true)
	{
	Debug.Log("Spawned 2");
	}
}

1 Answer

1

One way would be to use the Instantiate & Destroy methods.

  • Use the Instantiate function to create the character(s) of your choice, usually providing the position and orientation of the object. This is likely going to happen in your CharacterSpawnManager
  • Once complete, you can call the function Destroy(this.gameobject) from within the CharacterSpawnManager to remove it from the scene