Hi guys, so Im having scripting, or maybe Unity, issues. Im making a simple shooting script, and its just not working, despite it working earlier when it has very similar. Its reporting back no errors. About half an hour ago, my script wasnt compiling full stop, now it is (if I enter just a random word, it returns an error, so thats something), but usually when you fire a raycast with no target, an error is returned. Not with this, nor is it showing a debug ray when I try, or executing the effects of HitByGun.
Heres the script
#pragma strict
var AllowFire : boolean = true;
function Start () {
}
function Update () {
if (Input.GetButton("Fire1")){
if (AllowFire == true){
Shoot();
}
}
}
function Shoot(){
AllowFire = false;
var rayhit : RaycastHit;
//var PlayRanger = transform.TransformDirection(Vector3(0,0,10));
var PlayRanger = transform.forward;
if (Physics.Raycast((transform.position + Vector3.up * 0.75),PlayRanger, rayhit)){
rayhit.transform.SendMessage ("HitByGun");
Debug.DrawRay (transform.position, PlayRanger, Color.green);
}
yield WaitForSeconds (0.2);
AllowFire = true;
}
Any advice for me?