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);
    }
}

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#...

2 Answers

2

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.

Hah, I don't remember where I found it initially. I think I ran across it sometime when I was reading some blog posts about Unity workflow optimization.

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.