Instantiate() Argument error
Hey,
I want to use the Instansiate function to clone a prefab. I have a empty parent object that should emit those prefabs. But when I want to Instantiate the object, the function wants me to enter a Transform and not a Vector3. I don't understand this error because in the Documentation it says that it should work with a position and a object assigned.
GameObject logPrefab;
GameObject spawnObject;
string logPath;
Vector3 spawnPosition;
// Use this for initialization
void Start()
{
spawnObject = GameObject.Find("obstacleSpawn");
logPath = "models/log";
logPrefab = (GameObject)Resources.Load(logPath);
Debug.Log(logPrefab);
createWoodLog();
spawnPosition = new Vector3(14, 27, 12);
}
// Update is called once per frames
void Update()
{
}
void createWoodLog()
{
Instantiate(logPrefab, spawnPosition);
}
And the error
Assets/Resources/script/SpawningScript.cs(39,9): error CS1503: Argument `#2' cannot convert `UnityEngine.Vector3' expression to type `UnityEngine.Transform'
Comment
Answer by Paricus · Dec 04, 2016 at 08:33 PM
You're setting the spawnPosition after you've already called createWoodLog();
Also you need to add a rotation to the instantiate function.
Instantiate(logPrefab, spawnPosition,Quaternion.Identity);