- Home /
Problem doing a script.
This is the error message I get.
Assets/Scipt0/Gun.js(22,20): BCE0023: No appropriate version of 'UnityEngine.Object.Instantiate' for the argument list '(UnityEngine.Transform, UnityEngine.Vector3, UnityEngine.Vector3)' was found.
This is my script.
var sparks : Transform;
var ammo : int = 100;
var fireRate : float = 0.2;
private var nextFire : float = 0.0;
function Update () {
if(Input.Getbutton("Fire1")){
if(Time.time > nextFire){
nextFire = Time.time + fireRate;
fire();
}
}
}
function fire(){
var range = Mathf.Infinity;
var ray = Camera.main.ScreenPointToRay (Input.mousePosition);
var hit : RaycastHit;
if (Physics.Raycast (ray, hit, range)) {
Instantiate(sparks, hit.point, hit.normal);
}
}
Old habits die hard, so, might as well start off doing things right and get your script formatted correctly in the code box so we can read it.
It looks right when I go in to edit it, so I don't know why it comes out like this, shouldn't be that hard to decipher...
No problem, I'll try to make it easier to read now, I completely understand what you mean, I'm asking for help so there is no need to make it more difficult on who is helping me.
Answer by Zergling103 · Dec 20, 2011 at 01:56 AM
Here:
var sparks : Transform;
var ammo : int = 100;
var fireRate : float = 0.2;
private var nextFire : float = 0.0;
function Update () {
if(Input.Getbutton("Fire1") && Time.time > nextFire) {
nextFire = Time.time + fireRate;
fire();
}
}
function fire() {
var range = Mathf.Infinity;
var ray = Camera.main.ScreenPointToRay (Input.mousePosition);
var hit : RaycastHit;
if (Physics.Raycast (ray, hit, range)) {
// --------------------------------------------------------------
Instantiate(sparks, hit.point, Quaternion.LookRotation(hit.normal));
// --------------------------------------------------------------
}
}
:)
Instantiate requres a special rotation structure called a Quaternion be used to describe it's starting rotation. Quaternion.LookRotation() does basically what you intended by figuring out what rotation is requried to look at a point in space when standing at (0,0,0).
Thanks dude, I'll make sure not to make the mistake again :P
How do I do that? Sorry, I only made this Profile to ask this certain question, I'm new to this, bare with me and I'll give you the +1 if you tell me how, god, I'm such a noob. -_-;
See the thumb up icon by my answer? :) That.
Don't worry about looking like a noob. xD
Answer by save · Dec 20, 2011 at 12:51 AM
Instantiate takes three parameters, the object, the position and the rotation. The rotation has to be a quaternion. Is there a reason you're using the normal from hit? Otherwise switch it to Quaternion.identity
or the desired Quaternion.Euler(x, y, z)
.
Sorry, I really don't understand this, I'm just learning how to use Unity, I'm not too familiar with scripting or anything.
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Error line 22! Help. i dont know why? 1 Answer
Wierd error messages concerning audio play and pause? 1 Answer
Make player unable to shoot when reloading 3 Answers
Error CS1502 Help! 1 Answer