darkal
1
i want the item to be be spawned at the location of a empty game object i have the variables all ready made if u need the whole script comment and ill post it
function Update ()
{
if (drop)
{
Instantiate (clone);
Instantiate (clone1);
drop = false;
Destroy (pick);
}
}
You have to use Instantiate overload and provide position and location of the instantiated object. Assuming emptyObject is a GameObject, you can use:
Instantiate(clone, emptyObject.transform.position, Quaternion.identity);
// Create an empty object in scene
// Attach this script to any object in scene
// See: emptyObject.transform.position, emptyObject.transform.rotation
// Location and rotation are params 2 & 3 of Instantiate()
var emptyObject : Transform; // Drag empty object here
var drop = false;
var clone : Transform; // Drag your clone obj here
function Start() {
drop = true;
}
function Update ()
{
if (drop)
{
Instantiate (clone, emptyObject.transform.position, emptyObject.transform.rotation);
drop = false;
}
}
Alright but what if there’s instances for spawn points how do I get the items to spawn at the locations these spawn points are located at?
public float spawnTime;
private GameObject respawnPrefab;
// Use this for initialization
void Start () {
respawnPrefab = GameObject.Find("BallSpawnPoint");
InvokeRepeating("BallSpawn", 0, spawnTime);
}
void BallSpawn () {
var ball = Resources.Load("Ball");
Instantiate(ball, respawnPrefab.GetComponent<Transform>().position, respawnPrefab.GetComponent <Transform>().rotation);
}