I am having a bit of an issue with getting an empty bullet shell to clone every time a bullet is shot. The first empty shell appears and drops, but after the first empty shell, nothing is cloned.
I am struggling to figure out what the issue is. I am trying it on the first initial weapon before trying other weapons. My code is as follows:
using UnityEngine;
using System.Collections;
using System;
public class RecoilScript : MonoBehaviour {
public GameObject PistolRecoil;
public GameObject RifleRecoil;
public GameObject ShotgunRecoil;
// Use this for initialization
void Start () {
PistolRecoil.SetActive(false);
RifleRecoil.SetActive(false);
ShotgunRecoil.SetActive(false);
}
// Update is called once per frame
void Update () {
if (Input.GetKey(KeyCode.LeftControl) && SoldierController.canFire == true)
{
if (SoldierController.weaponType == 1)
{
PistolRecoil.SetActive(true);
RifleRecoil.SetActive(false);
ShotgunRecoil.SetActive(false);
StartCoroutine(recoilClone());
}
else if (SoldierController.weaponType == 2)
{
PistolRecoil.SetActive(false);
RifleRecoil.SetActive(true);
ShotgunRecoil.SetActive(false);
}
else if (SoldierController.weaponType == 3)
{
PistolRecoil.SetActive(false);
RifleRecoil.SetActive(false);
ShotgunRecoil.SetActive(false);
}
else if (SoldierController.weaponType == 4)
{
PistolRecoil.SetActive(false);
RifleRecoil.SetActive(false);
ShotgunRecoil.SetActive(true);
}
}
}
IEnumerator recoilClone()
{
Instantiate(PistolRecoil, SoldierController.positionGun, transform.root.rotation);
yield return new WaitForSeconds(0.5f);
Destroy(PistolRecoil);
//throw new NotImplementedException();
}
}