ballincreaserr()
is called by another script. ballincreaserr()
runs and the variable increases. balldecreaser()
also runs but the variable doesn’t decrease…
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class gameoverdetector : MonoBehaviour
{
Rigidbody2D rb;
//public powerrup other;
public float numberofballs;
void Start()
{
rb = GetComponent<Rigidbody2D>();
}
void Update()
{
if (rb.velocity.magnitude > 10)
{
rb.velocity = Vector2.ClampMagnitude(rb.velocity, 10);
}
if (numberofballs <= 0)
{
Debug.Log("Game Over");
}
}
public void ballincreaserr()
{
numberofballs++;
Debug.Log("BALL INCREASE");
}
public void balldecreaser()
{
numberofballs--;
Debug.Log("BALL DECREASE");
}
public void OnCollisionEnter2D(Collision2D col)
{
if (col.gameObject.name == "bottom")
{
balldecreaser();
Destroy(gameObject);
}
}
}