Trying to create scripts for my first outside tutorial game

Greetings unity community. I am creating a clicker game as my first outside of tutorial game. The game has a mechanic that allows you to kill mobs and receive coins once they are defeated. because I’m still new to unity i’m not sure how that script should look. the main problem i’m having is making it so you don’t receive the coins until the mob is dead, basically the mobs hp drops to 0 and he disappears, only then you get the coins.

I am also having trouble making a script increasing the health of the mob after each level so it becomes progressively stronger.

Have you made a script yet?

been thinking about how to put it together wrote down a base but not sure how i would even make it so that when the hp hits and how to track it then you would get the coins, i have yet to even implement a health script yet cause the main thing i need for the health is so it increases every level, i know how to change a value based on the clicks but not how to use another script to track it and then give a pay out

sorry for not uploading anything here, been busy with my own projects, but here is something you can try ouyt :

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class MonsterHealt : MonoBehaviour {
    public float Damage;
    public float Healt;
    public float CurrentCoins;

    public GameManager CurrentGameManager;
    // Use this for initialization
    void Start () {
        CurrentGameManager = GameObject.FindObjectOfType<GameManager> ();
    }
  
    // Update is called once per frame
    void Update () {

        if (Healt <= 0){//This says if the healt is zero (or less than zero because sometimes it can glitch)
            CurrentGameManager.CurrentCoins // this is the current amount of coins
                += //This says add to
                CurrentGameManager.HowManyCoinstogive;//this is how much to add to the coins (i put it as a variable so that you can change it later)
            Destroy (gameObject);// then it destroys the object (self explainatory)
        }
    }
    void OnMouseOver(){//On mouse over means when the mouse is over, but you must have a collider to work
        if (Input.GetKeyDown (KeyCode.Mouse0)){// Means that when the left button of the mouse (Mouse0) is pressed
            Healt -= CurrentGameManager.CurrentDamage; //Then remove healt, and remove it by the damage amount
        }
    }
}

and

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class GameManager : MonoBehaviour {// this is basicly to store the info that is public ()
    public float CurrentDamage;
    public float CurrentCoins;
    public float HowManyCoinstogive;
    // Use this for initialization
    void Start () {
    }
  
    // Update is called once per frame
    void Update () {
      
    }
}

i added messages to help you understand better, if you already know here is the monster healt script withouth messages

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class MonsterHealt : MonoBehaviour {
    public float Damage;
    public float Healt;
    public float CurrentCoins;

    public GameManager CurrentGameManager;
    // Use this for initialization
    void Start () {
        CurrentGameManager = GameObject.FindObjectOfType<GameManager> ();
    }
  
    // Update is called once per frame
    void Update () {

        if (Healt <= 0){
            CurrentGameManager.CurrentCoins += CurrentGameManager.HowManyCoinstogive;
            Destroy (gameObject);
        }
    }
    void OnMouseOver(){
        if (Input.GetKeyDown (KeyCode.Mouse0)){
            Healt -= CurrentGameManager.CurrentDamage;
        }
    }
}

also if you need any more help, feel free to ask me :smile: i will be happy to help :slight_smile:

thank you that helps alot

btw what you can do instead of having everything in update you can use Events or Delegates to Trigger a specific function whenever a specific goal has been met. like 0 Health could trigger end the game,

good point i might think about changing it a little so i can use some of that stuff outside of the script, thank you guys for helping me.