- Home /
The question is answered, right answer was accepted
[Unity 3.x Essentials, chap 02] BCE0023: No appropriate version of 'UnityEngine.Object.Instantiate'
hello everyone, i'm following the Book Unity 3.x GD Essentials (btw a great book) but i'm pretty stuck in the end of chapter 02 (and it's just the beginning xD) the goal is to create an instance of Prefab Bullet to shoot on a Wall. i did the scripting, re-read myself more than two times, compared with the step by step. but still getting an Error:
Assets/Shooter.js(13,55): BCE0023: No appropriate version of 'UnityEngine.Object.Instantiate' for the argument list '(UnityEngine.Rigidbody, UnityEngine.Vector3, UnityEngine.Vector3)' was found.
Here's the code done (attached to the camera):
var bullet : Rigidbody;
var power : float = 1500;
var moveSpeed : float = 5;
function Update () {
var h : float = Input.GetAxis("Horizontal") * Time.deltaTime * moveSpeed;
var v : float = Input.GetAxis("Vertical") * Time.deltaTime * moveSpeed;
transform.Translate(h, v, 0);
if (Input.GetButtonUp("Fire1"))
{
var instance : Rigidbody = Instantiate(bullet, transform.position, transform.position);
var fwd : Vector3 = transform.TransformDirection(Vector3.forward);
instance.AddForce(fwd * power);
}
}
i hope someone can help here, Thanks in Advance !!
Answer by Graham-Dunnett · Jul 01, 2012 at 12:25 AM
Go to:
http://docs.unity3d.com/Documentation/ScriptReference/index.html
This is the documentation page for Unity script. Search for "Instantiate" in the box top left. This will show you all Unity APIs that have the word Instantiate in them. You're doing this because the error message contains the word Instantiate, and tells you that line 13 of your code is the problem. (And I guess your line 13 is the one that called Instantiate.)
In the list that appears, select the top one, and you'll end up here:
http://docs.unity3d.com/Documentation/ScriptReference/Object.Instantiate.html
This is the documentation for the Instantiate function. At the top of the page you'll see:
static function Instantiate (original : Object, position : Vector3, rotation : Quaternion) : Object
This tells you that the Instantiate function takes 3 arguments, the last of which is a Quaternion. In your code you have passed in Transform.position as the last argument. The compiler is telling you that this is bad. Change your script to make the last argument Transform.rotation and you'll be golden.
Note: I have tried to tell you how you can help yourself, which I think is more valuable that answering your question directly.
Oww Gosh, i was sure i put rotation in the last argument, my eyes fooled me. Thannnnnks
Follow this Question
Related Questions
Unity 3 sealed class GameObject ? 3 Answers
Why is print() only in MonoBehaviour? 1 Answer
MD5 Implementation - Server Side High Score Problems 1 Answer
Problem with game resetting itself 0 Answers
Broken Script Help 1 Answer