my C# code in "HandgunReloading.cs":
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class HandgunReloading : MonoBehaviour
{
public AudioSource ReloadSound;
public GameObject CrossObject;
public GameObject MechanicsObject;
public int ClipCount;
public int ReserveCount;
public int ReloadAvailable;
public GunFire GunComponent;
// Start is called before the first frame update
void Start()
{
GunComponent = GetComponent();
}
// Update is called once per frame
void Update()
{
ClipCount = GlobalAmmo.LoadedAmmo;
ReserveCount = GlobalAmmo.CurrentAmmo;
if (ReserveCount == 0)
{
ReloadAvailable = 0;
}
else
{
ReloadAvailable = 10 - ClipCount;
}
if (Input.GetButtonDown("Reload"))
{
if (ReloadAvailable >= 1)
{
if (ReserveCount <= ReloadAvailable)
{
GlobalAmmo.LoadedAmmo += ReserveCount;
GlobalAmmo.CurrentAmmo -= ReserveCount;
ActionReload();
}
else
{
GlobalAmmo.LoadedAmmo += ReloadAvailable;
GlobalAmmo.CurrentAmmo -= ReloadAvailable;
ActionReload();
}
}
StartCoroutine(EnableScripts());
}
}
IEnumerator EnableScripts()
{
yield return new WaitForSeconds(1.1f);
GunFire.enabled = true; <-- error here
CrossObject.SetActive(true);
MechanicsObject.SetActive(true);
}
void ActionReload()
{
GunFire.enabled = false; <-- and here
CrossObject.SetActive(false);
MechanicsObject.SetActive(false);
ReloadSound.Play();
GetComponent().Play("HandgunReload");
}
}
I am using Visual Studio (Community)
and Unity 2018.3.0f2 (Personal)
Thanks in advance. :),C# code in "HandgunReloading.cs":
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class HandgunReloading : MonoBehaviour
{
public AudioSource ReloadSound;
public GameObject CrossObject;
public GameObject MechanicsObject;
public int ClipCount;
public int ReserveCount;
public int ReloadAvailable;
public GunFire GunComponent;
// Start is called before the first frame update
void Start()
{
GunComponent = GetComponent();
}
// Update is called once per frame
void Update()
{
ClipCount = GlobalAmmo.LoadedAmmo;
ReserveCount = GlobalAmmo.CurrentAmmo;
if (ReserveCount == 0)
{
ReloadAvailable = 0;
}
else
{
ReloadAvailable = 10 - ClipCount;
}
if (Input.GetButtonDown("Reload"))
{
if (ReloadAvailable >= 1)
{
if (ReserveCount <= ReloadAvailable)
{
GlobalAmmo.LoadedAmmo += ReserveCount;
GlobalAmmo.CurrentAmmo -= ReserveCount;
ActionReload();
}
else
{
GlobalAmmo.LoadedAmmo += ReloadAvailable;
GlobalAmmo.CurrentAmmo -= ReloadAvailable;
ActionReload();
}
}
StartCoroutine(EnableScripts());
}
}
IEnumerator EnableScripts()
{
yield return new WaitForSeconds(1.1f);
GunFire.enabled = true; <--- error here
CrossObject.SetActive(true);
MechanicsObject.SetActive(true);
}
void ActionReload()
{
GunFire.enabled = false; <--- and here
CrossObject.SetActive(false);
MechanicsObject.SetActive(false);
ReloadSound.Play();
GetComponent().Play("HandgunReload");
}
}
I am using Visual Studio (Community)
and Unity 2018.3.0f2 (Personal)
I can give any other information about my project if you say.
↧