hi, I’ve made this counter where score should increase if you catch heart and decrease when you run into fire, but it;s only showing me 100/100 score. That are the initial values I put for total life and life in the game. Can you help me, what is my mistake?
using System.Collections;
using System.Collections.Generic;
using System.Globalization;
using System.Net.NetworkInformation;
using UnityEngine;
using UnityEngine.UI;
public class destroygameobject : MonoBehaviour
{
private string lifeactually = "100";
private string lifetotal = "100";
private int lifeingame = 100;
public Text textforlife;
public GameObject particlesystem;
void Update()
{
textforlife.text = "Life " + lifeactually + "/" + lifetotal;
}
void OnCollisionEnter2D(Collision2D col)
{
if (col.gameObject.tag == "Heart")
{
// destroy this object
Destroy(col.gameObject);
Debug.Log("Object Destroyed");
particlesystem.SetActive(true);
if (lifeingame < 100)
{
lifeingame += 10;
lifeactually = lifeingame.ToString();
}
textforlife.GetComponent<UnityEngine.UI.Text>().text = "Life " + lifeactually + "/" + lifetotal;
}
else if (col.gameObject.tag == "Fire" && lifeingame > 0)
{
lifeingame -= 10;
lifeactually = lifeingame.ToString();
textforlife.GetComponent<UnityEngine.UI.Text>().text = "Life " + lifeactually +"/" + lifetotal;
}
else
{
Debug.Log("You died");
}
}
}