I keep running into an error that I had working. I am wondering what I did wrong. I have scanned time and time again, maybe someone knows another route or can lead me in the right direction, code below:
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
[RequireComponent(typeof(AudioSource))]
public class Pistol : MonoBehaviour
{
public Sprite idlePistol;
public Sprite shotPistol;
public float pistolDamage;
public float pistolRange;
public AudioClip shotSound;
public AudioClip reloadSound;
public AudioClip emptyGunSound;
public Text ammoText;
public int ammoAmount;
public int ammoClipSize;
int ammoLeft;
int ammoClipLeft;
bool isShot;
bool isReloading;
AudioSource source;
void Awake()
{
source = GetComponent();
ammoLeft = ammoAmount;
ammoClipLeft = ammoClipSize;
}
void Update()
{
ammoText.text = ammoClipLeft + “/” + ammoLeft;////////WhereI get error
if (Input.GetButtonDown(“Fire1”))
isShot = true;
if (Input.GetKeyDown(KeyCode.R))
{
Reload();////Get Error if I do not do below(NOTIMPLEMENTEDEXCEPTION)
}
}
private void Reload()
{
throw new NotImplementedException();
}
void FixedUpdate()
{
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
RaycastHit hit;
if (isShot == true && ammoClipLeft > 0 && isReloading == false)
{
isShot = false;
ammoClipLeft–;
source.PlayOneShot(shotSound);
StartCoroutine(“shot”);
if(Physics.Raycast(ray, out hit, pistolRange))
{
Debug.Log(“You’ve Collided with something.” + hit.collider.gameObject.name);
hit.collider.gameObject.SendMessage(“pistolHit”, pistolDamage, SendMessageOptions.DontRequireReceiver);
}
else if (isShot == true && ammoClipLeft <= 0 && isReloading == false)
{
isShot = false;
Reload();
}
}
void Reload()
{
int bulletsToReload = ammoClipSize - ammoClipLeft;
if(ammoLeft >= bulletsToReload)
{
StartCoroutine(“ReloadWeapon”);
ammoLeft -= bulletsToReload;
ammoClipLeft = ammoClipSize;
}
else if (ammoLeft < bulletsToReload && ammoLeft > 0)
{
StartCoroutine(“ReloadWeapon”);
ammoClipLeft += ammoLeft;
ammoLeft = 0;
}
else if (ammoLeft <= 0)
{
source.PlayOneShot(emptyGunSound);
}
}
IEnumerator ReloadWeapon()
{
isReloading = true;
source.PlayOneShot(reloadSound);
yield return new WaitForSeconds(2);
isReloading = false;
}
}
IEnumerator shot()
{
GetComponent().sprite = shotPistol;
yield return new WaitForSeconds(0.1f);
GetComponent().sprite = idlePistol;
}
}