I keep getting that "Instantiate" problem.

I keep getting the same error, can anybody help me by explaining why the problem appears, or at least give me the proper code?:

Assets/Scripts/TurretScript.js(72,17): BCE0023: No appropriate version of ‘UnityEngine.Object.Instantiate’ for the argument list ‘(System.Type,
UnityEngine.Vector3, UnityEngine.Quaternion)’ was found.


THE CODE:

function FireProjectile()
{
audio.Play();
nextFireTime = Time.time+reloadTime;
nextMoveTime = Time.time+firePauseTime;
CalculateAimError();

for(theMuzzlePos in muzzlePositions)
{
Instantiate (myProjectile, theMuzzlePos.position, theMuzzlePos.rotation);
Instantiate (muzzleEffect, theMuzzlePos.position, theMuzzlePos.rotation);
}
}

1 Answer

1

For one of your instantiate calls you may have a script called myProjectile or muzzleEffect and it’s using that rather than a variable that contains the prefab. Generally name your scripts using a capital letter to avoid this.

Another cause of this is defining variables like this:

   var somePrefab = GameObject;

When it should be like this:

   var somePrefab : GameObject;

You also need to assign the prefab in the inspector (which won’t work with the first example!)