I’ve been trying to make my gun scripts so that it fires and deals damage, but I can’s seem to get my gun to fire correctly, the bullet just appears where Im looking and won’t do enemy damage. Any suggestions on what I need to do?
oh soory, kinda new to thins stuff, my gun script is this
//Variables
var ammo : int = 100;
var fireRate : float = 0.0;
var sound : AudioClip;
var Effect : Transform;
var TheDammage = 100;
private var nextFire : float = 0.0;
//Functions
function Start ()
{
shoot = GetComponent(“Animator”);
}
function Update()
{
var hit : RaycastHit;
var ray : Ray = Camera.main.ScreenPointToRay(Vector3(Screen.width0.5, Screen.height0.5, 0));
if(Input.GetButtonDown("Fire1")&& ammo>0)
{
if (Physics.Raycast (ray, hit, 100))
{
var particleClone = Instantiate(Effect, hit.point, Quaternion.LookRotation(hit.normal));
Destroy(particleClone.gameObject, 2);
hit.transform.SendMessage("ApplyDammage", TheDammage, SendMessageOptions.DontRequireReceiver);
}
if(Time.time > nextFire)
{
nextFire = Time.time + fireRate;
GetComponent.<AudioSource>().Play();
ammo -= 1;
}
}
if(ammo <= 100)
{
if(Input.GetKeyDown("r"))
{
ammo = 100;
}
}
}
and my damage script is
function OnTriggerEnter (other : Collider)
{
if(other.tag == “Bullet”)
{
Destroy(gameObject);
}
}