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

Reference for a non static method between scripts

$
0
0
I am trying to take this method from my HealthManager.cs void LoadHealthSprites () { //array index 0 is 1 hit int spriteIndex = totalHealth -= 1; //will only run IF the there is a sprite at index[x] if (healthSprites[spriteIndex]) { this.GetComponent().sprite = healthSprites[spriteIndex]; } } and execute it on my LoseCollider.cs: void OnTriggerEnter2D (Collider2D trigger) { if (HealthManager.totalHealth >= 3) { HealthManager.LoadHealthSprites(); } else { levelManager = GameObject.FindObjectOfType(); levelManager.LoadLevel("Lose"); } } I get an error on this line from the LoseCollider.cs: HealthManager.LoadHealthSprites(); The error says: error CS0120: An object reference is required to access non-static member `HealthManager.LoadHealthSprites()' How do I create the reference to use the method?

Viewing all articles
Browse latest Browse all 2891

Trending Articles



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