Instantiate problem (7012)

var bullet = GameObject;

function Update () {

    if(Input.GetButtonUp("Jump")){
        var instance : GameObject = Instantiate(bullet, transform.position, transform.rotation);
    }
}

When I use that script I get the following error message:

Assets/launcher.js(6,56): BCE0023: No appropriate version of 'UnityEngine.Object.Instantiate' for the argument list '(System.Type, UnityEngine.Vector3, UnityEngine.Quaternion)' was found.

Any idea what I did wrong. In case you can't tell I'm new to both unity and scripting.

if the answer is correct then mark it with the check so that this site isn't loaded with more unanswered questions.

2 Answers

2

change this

var bullet = GameObject;

to this

var bullet : GameObject;

I get the same thing, but my script looks like this:

#pragma strict

var myProjectile = GameObject;
var reloadTime : float = 1f;
var turnSpeed : float = 5f;
var firePauseTime : float = .25f;
var muzzleEffect = GameObject;
var errorAmount : float = .001;
var myTarget : Transform;
var muzzlePositions : Transform;
var turretBall : Transform;

private var nextFireTime : float;
private var nextMoveTime : float;
private var desiredRotation : Quaternion;
private var aimError : float;

function Start () {

}

function Update ()
{
if(myTarget)
{
if(Time.time >= nextMoveTime)
{
CalculateAimPosition(myTarget.position);
turretBall.rotation = Quaternion.Lerp(turretBall.rotation, desiredRotation, Time.deltaTimeturnSpeed);
}
if(Time.time >= nextFireTime)
{
FireProjectile();
}
}
}
function OnTriggerEnter(other : Collider)
{
if(other.gameObject.tag == “Enemy”)
{
nextFireTime = Time.time+(reloadTime
0.5);
myTarget = other.gameObject.transform;
}
}
function OnTriggerExit(other : Collider)
{
if(other.gameObject.transform == myTarget)
{
myTarget = null;
}
}
function CalculateAimPosition(targetPos : Vector3)
{
var aimPoint = Vector3(targetPos.x+aimError, targetPos.y+aimError,targetPos.z+aimError);
desiredRotation = Quaternion.LookRotation(aimPoint);
}

function CalculateAimError()
{
aimError = Random.Range(-errorAmount, errorAmount);
}

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);
}
}

can anyone help me with this problem?

Don't post things which are not Solutions as answers - your problem is exactly the same - you are using = GameObject not : GameObject.