Quantcast
Channel: Questions in topic: "error message"
Viewing all articles
Browse latest Browse all 2891

Error CS0120: An object reference is required for the non-static field, method, or property 'Behaviour.enabled'

$
0
0
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.

Viewing all articles
Browse latest Browse all 2891

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>