I have a raycast script and i want to make it so that the ray gets casted from the end of my gun, so that when i click my mouse button the ray is created at the end of my gun and travel foward wherever my gun is pointed.
Here is my script:
var endBarrel :Transform;
var sound : AudioClip;
var TheDamage = 100;
var Effect : Transform;
var Enemy : GameObject[];
function Start() {
}
function Update(){
var hit : RaycastHit;
var ray = Camera.main.ScreenPointToRay(Vector3(Screen.width*0.5, Screen.height*0.5, 0));
if (Physics.Raycast (ray, hit, 100)) {
hit.transform.SendMessage("ApplyDamage", TheDamage, SendMessageOptions.DontRequireReceiver);
}
if(Input.GetButtonDown("Fire1")){
// you can use PlayOneShot to specify the sound...
audio.PlayOneShot(sound);
audio.Play();
}
if (Input.GetMouseButtonDown(0)){
if (Physics.Raycast (endBarrel.position, transform.forward, 100))
{
}
}
}