Hey all!
I’m having a hard time scaling a sprite smoothly.
I’ve tried a few different ways but I it keeps scaling instantly.
Here’s what I have:
void Update ()
{
ballSize = this.gameObject.transform.localScale;
//enemyBallSize = enemyBall.transform.localScale;
DestroyBall ();
scaleSpeed = Time.deltaTime * 30;
}
void OnCollisionEnter2D(Collision2D coll) {
enemyScale = coll.gameObject.transform.localScale.x;
if (coll.gameObject.transform.localScale.x < ballSize.y)
{
currentSize = this.transform.localScale.x;
this.transform.localScale = (new Vector2(currentSize, currentSize) + new Vector2(scale * scaleSpeed, scale * scaleSpeed));
}
Right now, when there is a collision, the ball increases in size but it’s instant. I want to be able to have it increase over like 1 second or something, and if possible I would like to have the ball increase past the size it’s meant to reach, before scaling down to it’s new size, like a bounce affect.
Thanks a lot!
I found this as the easiest way for me:
float scale = 0.01f;
void Update()
{
scale += 0.05f;
transform.localScale = new Vector2(scale, scale);
if (scale >= 1f)
Destroy(gameObject);
}