So I have a problem that sometimes i have double count of my points, and thats strange and don't need of it. Its strange glitch. Where i'm wrong on my script?
Regular is 500, and sometimes it gives 1000
Where can be a problem?
Below I leave two scripts
One is on Collectible objects:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Collectibles : MonoBehaviour {
public int scoreValue;
void OnTriggerEnter2D (Collider2D col) {
if (col.gameObject.layer == LayerMask.NameToLayer ("Player")) {
ScoreManager.score += scoreValue;
ScoreManager.collected = true;
} else {
ScoreManager.collected = false;
}
}
}
And the Second is on my Score text ui:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using TMPro;
public class ScoreManager : MonoBehaviour {
Animator anim;
public static int score;
TextMeshProUGUI text;
public static bool collected;
public float min;
public float max;
public float t;
void Awake()
{
text = GetComponent ();
score = 0;
}
void Start()
{
anim = GetComponent ();
collected = false;
}
void Update () {
text.text = score + " PTS";
if (score > 0)
{
anim.SetBool ("Points", true);
}
if (collected == true) {
t = Time.time;
text.fontSize = Mathf.Lerp (min, max, t);
collected = false;
} else {
t = Time.time;
text.fontSize = Mathf.Lerp (max, min, t);
}
}
}
↧