Hello, I have a problem, so basically I am making a game where you try to catch balls that are falling from the sky. Now, I made a script that adds a point, plays a sound and destroys the ball every time it collides with the player object.
Script :
public AudioSource tickSource;
public Text text;
public SpawnTimeUpgrade cost;
public float points;
void Start ()
{
tickSource = GetComponent<AudioSource> ();
}
public void OnCollisionEnter2D (Collision2D col)
{
if(col.gameObject.name == "New Sprite(Clone)")
{
tickSource.Play ();
points += 1;
text.text = points.ToString() + " POINTS";
Destroy(col.gameObject);
}
}
I also have an upgrade button that spends your points in order to get better stuff.
Script :
public Catch points;
public SpawnItems spawnTime;
public float cost;
public int count;
private float baseCost;
void Start ()
{
baseCost = cost;
}
public void PurchasedItem ()
{
if (points.points >= cost) {
points.points -= cost;
count += 1;
spawnTime.spawnTime -= 0.1f;
cost = Mathf.Round (baseCost * Mathf.Pow (1.15f, count));
}
}
Now the problem with this is when I buy the upgrade, the points don’t update, they update only when the ball collides with the player object again, I have tried many stuff, but I cannot get it to work. So basically all I want is the points to update once you buy an upgrade. Which for me as a beginner is quite hard…