TargetEdited.cs 1.05 KB
using UnityEngine;
using System.Collections;

public class TargetEdited : MonoBehaviour
{

	public GameObject objWorkingOn;
	public TextMesh damage_text;
	TextMesh text;

	//Used to check if the target has been hit
	public bool isHit = false;
	public float target_hp;

	public int shield;
	public int damage;

	int count = 30;
	bool counting = false;

	public int npc_no;

    private void Awake()
    {
		Debug.Log(objWorkingOn.name);
    }
    private void Update()
	{
		
		//If the target is hit
		if (isHit == true)
		{
			target_hp -= damage * (target_hp + shield);
			damage_text.text = damage.ToString();
			text = Instantiate(damage_text, objWorkingOn.transform.position, new Quaternion(0, 0, 0, 0));
			counting = true;
			isHit = false;
		}

		if (counting)
        {
			count -= 1;
			if (count < 1)
			{
				count = 30;
				counting = false;
				Destroy(text);
			}
		}


		if (target_hp < 1)
		{
			Destroy(objWorkingOn);
			Destroy(text);

			if (npc_no == 1)
			{
				GameObject.Find("MainFrame").GetComponent<ChangeScene>().ChangeGameMode();
			}

		}
		
	}

}