- Home /
BCE0044: expecting (,found 'RayShoot'
hi i just made this script today and i came across this error could someone please help me fix this im new to scripting.
var Range : float = 1000;
var Force : float = 1000;
function Update () {
if(Input.Getkey(KeyCode.F)){
RayShoot();
}
function RayShoot () {
var Hit : RaycastHit;
var DirectionRay = transform.TransformDirection(Vector3.forward);
Debug.DrawRay(transform.position , DirectionRay * Range , Color.blue);
if(Physics.Raycast(transform.position , DirectionRay , Hit, Range)){
}
}
Comment
Answer by robertbu · Oct 25, 2014 at 04:53 AM
You are missing a closing bracket for the 'if()' clause on line 5. See the '}' inserted in the revised code below. That missing bracket is causing the error. In addition, the function is GetKey() with an upper case 'K'. Note that GetKey() returns true for every frame, so your RayShoot() code will fire every frame the 'F' key is held down. If you want it to only fire once on a keypress, use GetKeyDown(). Here is your code with the changes:
#pragma strict
var Range : float = 1000;
var Force : float = 1000;
function Update () {
if(Input.GetKey(KeyCode.F)) {
RayShoot();
}
}
function RayShoot () {
var Hit : RaycastHit;
var DirectionRay = transform.TransformDirection(Vector3.forward);
Debug.DrawRay(transform.position , DirectionRay * Range , Color.blue);
if(Physics.Raycast(transform.position , DirectionRay , Hit, Range)){
}
}
P.S. For future posts, please format your code. After pasting, select your code and use the 101/010 button. I did it for you this time.