Hello Guys!
I am making a game like Agar.io, as you know the when the player eats food(dots), it grows, it is
not the problem but when the player gets small(by throwing food from itself), I don’t want it to get smaller than it’s original scale.
So Please Help!
I hope you understand my question, if not, then tell me I will try to explain more.
Thanks in Advance!
{
public float Increase;
public float Decrease;
void Start()
{
}
void OnTriggerEnter(Collider other)
{
if (other.gameObject.CompareTag("Food"))
{
transform.localScale += new Vector3(Increase, Increase, 0f); // value of increase = 0.2
Destroy(other.gameObject);
}
}
void Update()
{
if (Input.GetMouseButtonDown(0))
{
transform.localScale += new Vector3(Decrease, Decrease, 0f); // value of decrease = 0.5
}
}
}
private Vector3 _originalLocalScale;
private void Start()
{
_originalLocalScale = transform.localScale;
}
private void Update()
{
if (Input.GetMouseButtonDown(0))
{
var toChange = _originalLocalScale + new Vector3(Decrease, Decrease, 0f);
if (toChange.x >= _originalLocalScale.x && toChange.y >= _originalLocalScale.y)
{
transform.localScale = toChange;
}
}
}
This should do the trick. @ArsalanP