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

Adding score when enemy dies (Errors)

$
0
0
Hi, I have the following 2 codes: Enemy Health: using UnityEngine; using System.Collections; public class EnemyHealth : MonoBehaviour { public float health = 10.0f; public float score = 0f; public void Damage( float amt ) { health -= amt; if(health <= 0) { Die(); score++; } } void Die() { Destroy (gameObject); } } Score: using UnityEngine; using System.Collections; public class Score : MonoBehaviour { public void OnGUI() { GUI.color = Color.red; GUI.Label(new Rect(10, 30, 60, 20), "Score: " + EnemyHealth.score); } } and I get the following errors: 1. Assets/Standard Assets/Scripts/Score.cs(9,12): error CS1503: Argument `#2' cannot convert `object' expression to type `string' 2. Assets/Standard Assets/Scripts/Score.cs(9,12): error CS1502: The best overloaded method match for `UnityEngine.GUI.Label(UnityEngine.Rect, string)' has some invalid arguments 3. Assets/Standard Assets/Scripts/Score.cs(9,68): error CS0120: An object reference is required to access non-static member `EnemyHealth.score' What am I doing wrong? I know I have to make it public but how do I go about doing this? Thanks

Viewing all articles
Browse latest Browse all 7934

Trending Articles



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