**I need to update the Score when an Enemy is destroyed by my character. I’m new to C# but I do have some experience in programming.
Here are my two scripts that I am working with… I would like to implement the “addPoints” function of ScoreScript into the part of HealthScript that destroys the enemy when the hp is 0.
Health for enemy**
using UnityEngine;
using System.Collections;
public class HealthScript : MonoBehaviour {
public int hp = 1;
public bool isEnemy = true;
public void Damage(int damageCount)
{
hp -= damageCount;
if (hp <= 0)
{
Destroy (gameObject);
}
}
void OnTriggerEnter2D(Collider2D otherCollider)
{
ShotScript shot = otherCollider.gameObject.GetComponent<ShotScript> ();
if(shot != null)
{
if(shot.isEnemyShot != isEnemy)
{
Damage(shot.damage);
Destroy(shot.gameObject);
}
}
}
}
Score Script
using UnityEngine;
using System.Collections;
public class Score : MonoBehaviour
{
public int score = 0; // The player's score.
private PlatformerCharacter2D playerControl; // Reference to the player control script.
private int previousScore = 0; // The score in the previous frame.
void Awake ()
{
// Setting up the reference.
playerControl = GameObject.FindGameObjectWithTag("Player").GetComponent<PlatformerCharacter2D>();
}
public void addPoints() {
score = score + 88;
}
void Update ()
{
// Set the score text.
guiText.text = "Score: " + score;
// If the score has changed...
if(previousScore != score)
// ... play a taunt.
// Set the previous score to this frame's score.
previousScore = score;
}
}