I need help with instantiate - Overloads
theres 2 errors which says : the best overloaded method,argument #3 cant convert...
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class bulletDestruction : MonoBehaviour {
public GameObject particleEffect;
public Transform particleSpawn;
void OnCollisionEnter()
{
Destroy ();
}
void Destroy()
{
Instantiate (particleEffect,particleSpawn,particleSpawn.rotation);
Destroy (gameObject);
}
}
Answer by meat5000 · Mar 01, 2018 at 10:01 AM
You should not create a Function with the name of an existing method. Destroy already exists and you may well confuse the compiler by calling Destroy(object) from within a function called Destroy(). You are redefining the function so to speak. You also need to reference the transform position for your Vector3 and not the whole Transform.
void OnCollisionEnter()
{
DestroyGO ();
}
void DestroyGO()
{
Instantiate (particleEffect,particleSpawn.position,particleSpawn.rotation);
Destroy (gameObject);
}
If you look at Instantiate in the scripting API youll see at the top of the page a list of 5 versions of Instantiate. These are 'Overloads' and you must match one of those patterns. It is this to which the error specifically refers. You can see that as Argument #2 in your Instantiate is actually referring to Transform. As a result it looks at the list of Overloads and picks the one this currently fits. This would either be #3 Nothing or #3 bool instantiateInWorldSpace as that's what is in the Overloads that have the pattern 'Instantiate(Object,Transform'
. When it sees the rotation it gets confused and can no longer find a matching Overload, hence why it says #3.
Answer by upasnavig90 · Mar 01, 2018 at 09:56 AM
https://docs.unity3d.com/ScriptReference/Object.Instantiate.html
instead of rotation u need to use quaternion. public void Instantiate(Object original, Vector3 position, Quaternion rotation);
And also he has to use Position and not Transform as he is using! ;D
Answer by HeresJohnny123 · Mar 01, 2018 at 10:01 AM
The problem i can see is that you are using particlespawn to set the place where to spawn the object. But it's asking for a vector and not a transform.
Meaning that the instantiate part should look like this:
Instantiate (particleEffect,particleSpawn.position,particleSpawn.rotation);
Since transform.position = vector
Your answer
Follow this Question
Related Questions
randomly shoot using number generator 0 Answers
Bullets are firing in the wrong direction. 1 Answer
Moving a spawned shuriken 2 Answers
Time between bullet shots increasing each time? 0 Answers
Instantiate() Argument error 1 Answer