Cannot convert UnitEngine.Vector3 to UnityEngine.Transform when using .postition
Hey,
I am trying to make a simple spawning system for my enemies. I have an array of all the spawnpoints, then when spawning a zombie I pick a random spawnpoint from this array, and instantiate a zombie there. The problem is, as soon as I do:
Instantiate(zombiePrefab, selectedSpawn.gameObject.transform.position);
I get the error mentioned in the title. The spawnpoints are empty gameobjects.
Answer by sunderplugs11 · Aug 15, 2017 at 01:54 PM
https://docs.unity3d.com/ScriptReference/Object.Instantiate.html
look at the top of alll the ways you can type it in
the only one with 2 parameters needs a Prefab, and a Transform
you are putting in a Prefab, and a Vector3.
you can either do
Instantiate(zombiePrefab, selectedSpawn.gameObject.transform);
or
Instantiate(zombiePrefab, selectedSpawn.gameObject.transform.position, selectedSpawn.gameObject.transform.rotation);
actually, you probably can just use selectedSpawn.tranform
Adding the rotation part worked, but they aren't moving at all after spawning. Do I need to add something?
I don't know how to fix that, but you left me on a cliff hanger. Did you fix the problem? I don't know why but I want to know, I feel like I can't go to sleep with out knowing what happened to you.
Your answer
Follow this Question
Related Questions
What is different when Instantiate set Prefab Position? 1 Answer
How to store a position that is moving to create a prefab to spawn at the exact position 1 Answer
Instantiate prefab if no prefab exists at location 1 Answer
Instantiated prefab has a z-axis of 90 0 Answers
Instantiated prefab trying to keep weird Y position 0 Answers