I’ve a battle scene where two people (protagonist and enemy) fight. I’ve created a button (“Continue”) to go to another scene. The problem is that I want that button to appear only if enemy’s HP are < or = to 0. Enemy’s script (HP part) (Oh, PV=HP and Enemigo=Enemy)
if (EnemigoPV <= 0) { GetComponent().SetTrigger(“isDying”); GetComponent().Stop(); } } }
I want something like “If EnemyHP is < or = to 0, button Continue appears”.
Yep, use code tags. And you already have your condition check figured out, so within that, just call a manager script with a method to set the button gameobject active.
This will turn off the buttonImage gameObject. If buttonImage is not a gameobject variable, then yes, you can use that code to turn it off. Or true to turn it on.
If buttonImage is a gameobject variable, then you can take out the gameObject part as it already is a gameObject.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
[RequireComponent(typeof(AudioSource))]
public class Enemy : MonoBehaviour {
public static float EnemigoPV = 80;
public static float EnemigoMaxPV = 80;
public Transform damTextObj2;
public GameObject buttonImage;
// Use this for initialization
void Start () {
AudioSource audio = GetComponent<AudioSource>();
audio.Play();
buttonImage.gameObject.SetActive(false);
}
// Update is called once per frame
void Update()
{
if ((Input.GetKeyDown("2")))
{
BattleFlow.currentDamage = 20;
GetComponent<Animator>().SetTrigger("isAttacking");
Instantiate(damTextObj2, new Vector3(59.4f, 1.806f, 65.32f), damTextObj2.rotation);
BattleFlow.damageDisplay = "z";
}
if (BattleFlow.damageDisplay == "y")
{
EnemigoPV -= BattleFlow.currentDamage;
Debug.Log (EnemigoPV);
BattleFlow.damageDisplay = "n";
}
if (EnemigoPV <= 0)
{
GetComponent<Animator>().SetTrigger("isDying");
GetComponent<AudioSource>().Stop();
buttonImage.SetActive(true);
}
}
}