Okay, so I’m working on a melee system of sorts, a mutated version of the launcher from the FPS tutorial. As far as I can tell there is nothing wrong with my script at all, but its giving me this error:
“UnityException: You are not allowed to call this function when declaring a variable.
Move it to the line after without a variable declaration.”
it says the error is on line 5. Line 5 in my script is an empty space!
Here is my script:
var meleeCollider : Rigidbody;
var speed = 20;
var swingTimer = 0.15;
private var lastSwing = -10.0;
function Update(){
if(Input.GetButtonDown("Fire1")){
if (Time.time > swingTimer + lastSwing){
var instantiatedProjectile : Rigidbody = Instantiate(meleeCollider, transform.position, transform.rotation);
instantiatedProjectile.velocity = transform.TransformDirection(Vector3(0,0,speed));
Physics.IgnoreCollision(instantiatedProjectile.collider, transform.root.collider);
lastSwing = Time.time;
}
}
}
What the hell does that stupid error mean?