I’m fairly new to unity and I need some help with a Reloading/Gun script. Here is the script.
using System;
using UnityEngine;
using System.Collections;
public class Gun : MonoBehaviour {
public float damage = 10f;
public float range = 100f;
public float fireRate = 20f;
public float impactForce = 300f;
public int maxAmmo = 10;
private int currentAmmo = 36;
public float reloadTime = 1f;
public Camera fpsCam;
public ParticleSystem muzzleFlash;
public GameObject impactEffect;
public AudioSource sounds;
public Animator animator;
private float nextTimeToFire = 0f;
private object Reloading;
void start ()
{
if (currentAmmo == -1)
currentAmmo = maxAmmo;
}
void Update() {
if (currentAmmo <= 0 )
Reload();
return;
if (Input.GetButton("Fire1") && Time.time >=nextTimeToFire)
{
nextTimeToFire = Time.time + 1f / fireRate;
Shoot();
}
}
void Reload()
{
Debug.Log(Reloading);
currentAmmo = maxAmmo;
}
void Shoot()
{
muzzleFlash.Play();
sounds.Play();
GetComponent<Animator>().Play("shooting");
currentAmmo--;
RaycastHit hit;
if (Physics.Raycast(fpsCam.transform.position, fpsCam.transform.forward, out hit, range))
{
Debug.Log(hit.transform.name);
Enemy enemy = hit.transform.GetComponent<Enemy>();
if (enemy != null)
{
enemy.TakeDamage(damage);
}
if (hit.rigidbody != null)
{
hit.rigidbody.AddForce(-hit.normal * impactForce);
}
GameObject impactGo = Instantiate(impactEffect, hit.point, Quaternion.LookRotation(hit.normal));
Destroy(impactGo, 2f);
}
}
}
internal class Enemy
{
internal void TakeDamage(float damage)
{
throw new NotImplementedException();
}
}