- Home /
Question by
Wesley21spelde · May 29, 2016 at 05:00 PM ·
instantiateprefabtransform.positionspawnpoints
Spawn At Spawnpoint
Hey guys
I tried to Spawn The Drone At the Position of the spawn point But It doen not work??
using UnityEngine;
using System.Collections;
public class Dronesspawn : MonoBehaviour
{
public Transform SpawnPoint;
public GameObject Drones;
public float spawnTime = 5f;
// Use this for initialization
void Start()
{
InvokeRepeating("DronesSpawn", spawnTime, spawnTime);
}
// Update is called once per frame
void Update()
{
}
void DronesSpawn ()
{
// I tried to Spawn The Drone At the Position of the spawn point ( The SpawnPoint Will Be moving!! ).But It Does not Work?
var newpDronesspawn = GameObject.Instantiate(Drones), SpawnPoint.transform.position,transform.rotation);
}
}
Comment
GameObject.Instantiate(Drones), SpawnPoint.transform.position,transform.rotation);
There are more ')' than '('... If you wrote that, Unity should display an error...
Is it Java or C# ? "var" is java but your functions seem to be C#...
You can use "var" in C#, as long as you also assign it something.
Answer by Raresh · May 29, 2016 at 05:09 PM
From the code you gave, the Instantiation doesn't look quite right.
var newpDroneSpawn = (GameObject) Instantiate(Drones,SpawnPoint.transform.position,transform.rotation);
Given that you set up the references properly, this will instantiate a drone at the current position of the spawnPoint.
Answer by DroidifyDevs · May 29, 2016 at 06:57 PM
Pretty simple in C#:
public Transform Spawnpoint;
public GameObject Spawnobject;
void Spawntheobject()
{
Instantiate(Spawnobject, Spawnpoint.transform.position, Quaternion.identity);
}
Also when asking questions don't say "it does not work". Please be as specific as possible as people answering your question have no idea about what you're seeing or your project.