Whats going wrong in my Scripts?
So I'm trying to make a First Person Shooter for mobile. I have these three scripts but every time i go near my 'enemy' my Gun floats off in to the air, I'm new to coding so have no idea what i've done wrong here
This script is on my Gun:
function OnGUI () { if (GUI.RepeatButton(Rect(10,70,50,30),"Shoot")) GoTriggerHappy(); }
function Update () { if (Input.GetAxis("Shoot")) GoTriggerHappy(); }
function GoTriggerHappy () {
if(Input.GetMouseButton(0)) {
var gunsound : AudioSource = GetComponent.<AudioSource>();
gunsound.Play();
GetComponent.<Animation>().Play("GunShot");
}
}
This is attached to an empty game object on my FirstPerson Character :
var DamageAmount : int = 5; var TargetDistance : float; var AllowedRange : float = 15;
function Update () { if(Input.GetMouseButton(0)) {
var Shot : RaycastHit;
if (Physics.Raycast (transform.position, transform.TransformDirection(Vector3.forward), Shot)) {
TargetDistance = Shot.distance;
if (TargetDistance < AllowedRange) {
Shot.transform.SendMessage("DeductPoint", DamageAmount);
}
}
}
}
and this is on what i want destroyed:
var EnemyHealth : int = 10;
function DeductPoints (DamageAmount : int) { EnemyHealth -= DamageAmount; }
function Update () { if (EnemyHealth <= 0) { Destroy(gameObject); } } Any help much appreciated
Thanks