Cannot convert 'UnityEngine.Quaternion' expression to type 'bool'
Hey ^^
I've been trying to instantiate a gameObject with a random rotation today but got this error all the time. The console also says:
"The best overloaded method match for 'UnityEngine.Object.Instantiate(UnityEngine.Object, UnityEngine.Transform, bool)' has some invalid arguments"
What confuses me most is that there isn't even a bool in the Instantiate function.
My code:
Spawnlocation = this.transform;
GameObject drop = Instantiate (Resources.Load ("wood_drop"), Spawnlocation, Quaternion.Euler(Random.Range(0,360),Random.Range(0,360),Random.Range(0,360))) as GameObject;
I would be glad if someone could help me with this mess.
Thank you in advance!
Answer by ScaniX · Aug 18, 2016 at 10:53 PM
Please check out https://docs.unity3d.com/ScriptReference/Object.Instantiate.html.
The compiler tries to find the best matching method signature for your call and decides to use :
public static Object Instantiate(Object original, Transform parent, bool worldPositionStays);
I guess you wanted to use one of these:
public static Object Instantiate(Object original, Vector3 position, Quaternion rotation);
public static Object Instantiate(Object original, Vector3 position, Quaternion rotation, Transform parent);
So your code should look like this:
GameObject drop = Instantiate (Resources.Load ("wood_drop"), Spawnlocation.position, Quaternion.Euler(Random.Range(0,360),Random.Range(0,360),Random.Range(0,360))) as GameObject;
or this (if you want to set the parent):
GameObject drop = Instantiate (Resources.Load ("wood_drop"), Vector3.zero, Quaternion.Euler(Random.Range(0,360),Random.Range(0,360),Random.Range(0,360)), Spawnlocation) as GameObject;