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

Object reference not set to an instance of an object

$
0
0
I get this error whenever I press 5: NullReferenceException: Object reference not set to an instance of an object WarriorSpin.Update () (at Assets/Scripts/SpellsAndAbilities/Warrior/WarriorSpin.cs:30) I have checked to make sure everything is the way it is supposed to be but it still doesn't work. Here is my code: using UnityEngine; using UnityEngine.UI; using System.Collections; public class WarriorSpin : MonoBehaviour { public GameObject player; public float coolDown; PlayerScript ps; public GameObject canvas; public GameObject errorMessageArea; void Start () { player = gameObject; ps = player.GetComponent (); canvas = GameObject.Find ("HudCanvas"); errorMessageArea = GameObject.Find ("ErrorMessageArea"); } void Update () { if (Input.GetButtonDown ("5")) { if (coolDown <= 0) { if (ps.mana > 50) { ps.isWarriorSpin = true; coolDown = 30; ps.mana -= 50; } else { GameObject notEnoughManaObject = Instantiate (ps.notEnoughMana, errorMessageArea.transform.position, errorMessageArea.transform.rotation) as GameObject; notEnoughManaObject.transform.SetParent (canvas.gameObject.transform); } } else { GameObject notReadyYetObject = Instantiate (ps.notReadyYet, errorMessageArea.transform.position, errorMessageArea.transform.rotation) as GameObject; notReadyYetObject.transform.SetParent (canvas.gameObject.transform); } } if (GetComponent () != null && coolDown > 1) { GetComponent ().text = "" + coolDown.ToString ("0"); } if (GetComponent () != null && coolDown > 0 && coolDown <= 1) { GetComponent ().text = "" + coolDown.ToString ("F1"); } if (GetComponent () != null && coolDown <= 0) { GetComponent ().text = ""; } coolDown -= Time.deltaTime; } }

Viewing all articles
Browse latest Browse all 7934


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