- Home /
Unity not recognizing Instantiate? JavaScript
I am trying to make a gun that shoots the bullets i made. Yet, when i finish the script i get one error...which is
"Assets/GUN/Shoot1.js(14,34): BCE0023: No appropriate version of 'UnityEngine.Object.Instantiate' for the argument list '(UnityEngine.Transform, UnityEngine.GameObject, UnityEngine.Vector3, UnityEngine.Quaternion)' was found."
Instantiate, for those who don't know, is for cloning objects. :D
Also this is the script...
#pragma strict
function Start () {
} public var Bullet : Transform; public var bulletSpeed : float = 6000;
function Update () { if (Input.GetButtonDown("Fire1")) { if (!Bullet || !bulletSpeed){ Debug.Log("[Shoot] 'Bullet' or 'bulletSpeed' is undefined"); } else { var bulletCreate = Instantiate(Bullet, GameObject.Find("SpawnPoint"),transform.position, Quaternion.identity); bulletCreate.rigidbody.AddForce(transform.forward * bulletSpeed); }
}
}
Format code when you post it, don't just leave it in a mess like that.
Answer by rutter · Apr 06, 2012 at 09:37 PM
You're passing four arguments to a function which expects a maximum of three. Of course that won't work.
Look at this expression:
Instantiate(Bullet, GameObject.Find("SpawnPoint"),transform.position, Quaternion.identity);
If I had to guess, you probably meant for the comma before transform.position
to be a period.
Your answer
Follow this Question
Related Questions
How to Instantiate prefab as child? (Java) 1 Answer
Instantiate 697283 trees by script? Crash! 2 Answers
Scripts not on instantiated GameObjects? 1 Answer
Need help combining code 1 Answer
Simple Java Script for Opening and Closing a Drawer 1 Answer