alright so here’s the thing, i have these two trigger box colliders, when i touch one i want my score to go a point lower, when i touch the other i want it to go a point higher
the negative one works just fine, but for some reason the other doesn’t
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using TMPro;
public class PUNTEGGIO : MonoBehaviour
{
public GameObject canvasObject2;
public GameObject canvasObject;
public float duration = 2f;
public float Score;
public GameObject panelObject;
[SerializeField] TextMeshProUGUI ScoreText;
// Start is called before the first frame update
void Start()
{
Score = 5;
}
// Update is called once per frame
void Update()
{
if(Score <= 0)
{
YouWin();
}
}
void YouWin()
{
canvasObject2.SetActive(false);
canvasObject.SetActive(true);
panelObject.SetActive(true);
ScoreText.text = "You lose!";
Time.timeScale = 0f;
}
private void OnTriggerEnter(Collider other)
{
if (other.CompareTag("Player"))
{
Addscore();
}
}
void Addscore()
{
Score--;
ScoreText.text = Score.ToString();
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using TMPro;
public class POWERUPPLUS : MonoBehaviour
{
public GameObject playa;
PUNTEGGIO punteggio;
public int points;
public GameObject pickupEffect;
public float duration = 4f;
// Start is called before the first frame update
void Start()
{
punteggio = playa.GetComponent<PUNTEGGIO>();
}
void OnTriggerEnter(Collider other)
{
{
if (other.CompareTag("Player"))
StartCoroutine(Pickup(other));
}
}
// Update is called once per frame
IEnumerator Pickup(Collider player)
{
Instantiate(pickupEffect, transform.position, transform.rotation);
punteggio.Score++;
GetComponent<MeshRenderer>().enabled = false;
GetComponent<Collider>().enabled = false;
Destroy(gameObject);
yield return new WaitForSeconds(duration);
}
}