- Home /
add and remove matches
so im new to a ammo system and not sure how add to the code I have. so basically I'm trying have the character be able to pick up a pack of matches and it add to the display on the screen then when you light a candle the display number goes down
I have a script to pick up matches, light candles, and a ui script (for stamina and health) I just need to know what i need to add
UI Script
using System.Collections;
using System.Collections.Generic;
using TMPro;
using UnityEngine;
public class UIScript : MonoBehaviour
{
[SerializeField] private TextMeshProUGUI healthText = default;
[SerializeField] private TextMeshProUGUI staminaText = default;
private void OnEnable()
{
FirstPerson.OnDamage += UpdateHealth;
FirstPerson.OnHeal += UpdateHealth;
FirstPerson.OnStaminaChange += UpdateStamina;
}
private void OnDisable()
{
FirstPerson.OnDamage -= UpdateHealth;
FirstPerson.OnHeal -= UpdateHealth;
FirstPerson.OnStaminaChange -= UpdateStamina;
}
private void Start()
{
UpdateHealth(100);
UpdateStamina(100);
}
private void UpdateHealth(float currentHealth)
{
healthText.text = currentHealth.ToString("00");
}
private void UpdateStamina(float currentStamina)
{
staminaText.text = currentStamina.ToString("00");
}
}
pick up match
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class pickupmatch : MonoBehaviour
{
public Text txt;//text
public GameObject match;
void OnTriggerStay(Collider target)
{
if (target.tag == "Player")
{
if (Input.GetKeyDown(KeyCode.E) && tlamp.activeInHierarchy == true)
{
txt.text = " ";
match.SetActive(false);
}
}
}
private void OnTriggerEnter(Collider coll)//entrance and exit to/from trigger
{
if ((coll.tag == "Player") && tlamp.activeInHierarchy == true)
{
txt.text = "E Pick Up match";
}
}
private void OnTriggerExit(Collider coll)//entrance and exit to/from trigger
{
if (coll.tag == "Player")
{
txt.text = " ";
}
}
}
light a candle
using UnityEngine;
using UnityEngine.UI;
public class lightacandle : MonoBehaviour
{
public Text txt;//text
public GameObject fire1;
void OnTriggerStay(Collider target)
{
if (target.tag == "Player")
{
if (Input.GetKeyDown(KeyCode.E))
{
txt.text = " ";
fire1.SetActive(true);
}
}
}
private void OnTriggerEnter(Collider coll)//entrance and exit to/from trigger
{
if ((coll.tag == "Player") && fire1.activeInHierarchy == false)
{
txt.text = "E to light";
}
}
private void OnTriggerExit(Collider coll)//entrance and exit to/from trigger
{
if (coll.tag == "Player")
{
txt.text = " ";
}
}
}
Your answer
Follow this Question
Related Questions
UI components all disappear on Play mode, then stay invisible 2 Answers
Display Emojis using its HTML code in a text 1 Answer
How to match UI Image size to UI Text size when using ContentSizeFitter on UI Text? 1 Answer
Instantiated UI objects with image components not appearing, rest of object works fine. 0 Answers
Fitting a parent UI element to a Child Text's Content 2 Answers