I am learning C#…
I have 2 scripts. One is on a pickup item ( a Heart object that adds points on pick up )
& an inventory script is attached to my main character … each object has a collider.
For some reason my score is not updating when I pick up a heart…
I believe " c.gameObject.SendMessage(“PickUpHealth”, c); " in the Health.cs script is not calling function PickUpHealth…
So my question is why ??
here are both scripts
public class Health : MonoBehaviour {
public float rotationSpeed = 100.0f;
public AudioClip powerSound;
public UILabel guiLevel;
public float itemValue;
void OnTriggerEnter (Collider c) {
if (c.gameObject.tag == "Player") {
Debug.Log("HELLO");
c.gameObject.SendMessage("PickUpHealth", c);
AudioSource.PlayClipAtPoint (powerSound, transform.position);
Destroy(gameObject);
}
}
}
// My Character Inventory SCRIPT
public class Inventory : MonoBehaviour {
public static int powerup = 0;
public AudioClip powerSound;
private GameObject itemPowerup;
private float score;
public UILabel guiLevel;
void Start () {
score = 1.0f;
}
void PickUpHealth(Collider c){
if(c.CompareTag("heart")) {
Debug.Log (" Eddie collided with a heart ");
score += c.gameObject.GetComponent ().itemValue;
guiLevel.text = "Score: " + score;
// AudioSource.PlayClipAtPoint (powerSound, transform.position);
//Destroy(gameObject);
}
}
}