Hello everyone i have a raycast script here for a gun but it only makes the ray thing in the center of the screen, i want it so tha the ray will come out the barrel of my gun, could anyone help me?..
Here is my script:
var Effect : Transform;
var TheDamage = 100;
var sound : AudioClip;
function Update () {
if(Input.GetButtonDown("Fire1")){
audio.PlayOneShot(sound);
audio.Play();
}
var hit : RaycastHit;
var ray : Ray = Camera.main.ScreenPointToRay(Vector3(Screen.width*0.5, Screen.height*0.5, 0));
if (Input.GetMouseButtonDown(0)){
if (Physics.Raycast (ray, hit, 100))
{
var particleClone = Instantiate(Effect, hit.point, Quaternion.LookRotation(hit.normal));
Destroy(particleClone.gameObject, 2);
hit.transform.SendMessage("ApplyDamage", TheDamage, SendMessageOptions.DontRequireReceiver);
}
}
}