Hello everyone, im trying to call a function that scales down 15-20 spheres by the press of a buy button(space button) from the script where I keep the points. The space key will eventually be replaced by a button with a click activation on the canvas.
public class BuyStuffScript : MonoBehaviour
{
public int cost=0;
public CircleSize circlesize;
void Update()
{
int score = Lava_Points.score;
if (score >= cost){
if (Input.GetKeyDown("space"))
{
Debug.Log("space");
circlesize.DecreaseCircle();
Debug.Log("space2");
Lava_Points.score -= cost;
}
}
}
}
But when I call the function from my other script that scales down the object, I think it does not know what object to scale down. This my script that scales down the sphere:
public class CircleSize : MonoBehaviour
{
public GameObject circle;
public float decreasingfactor = 0.9f;
void Start()
{
}
void Update()
{
if (Input.GetKeyDown("k"))
{
Debug.Log("k");
DecreaseCircle();
}
}
public void DecreaseCircle()
{
Debug.Log("Decreased");
circle.transform.localScale *= decreasingfactor;
}
}
When I try to scale down the spheres which all have the CircleSize script attached by pressing ‘k’, therefore just using the CircleSize script, it does work, but I think I want to keep score and calling a function that scales down a gameobject seperate. First of all, does my though process make sense in keeping those seperated? If so, how would I approach such a thing?
Thank you!