Scaling objects over time?

I have a chest that I applied a script to, I’m trying to make objects start small while in the chest and as they’re popping out of the chest get to regular scale. This is part of the script that I just added:

 GameObject justDropped; 
                float newScale = Mathf.Lerp(1, 5, Time.time / 5);
                if (randomValue <= LootTable[j].dropRarity)
                    
                {
                    
                    Vector3 direction = new Vector3(Random.Range(1, 3), 3, Random.Range(-2, 2)); 
                    justDropped = Instantiate(LootTable[j].item, transform.position, Quaternion.identity); 
                    justDropped.GetComponent<Rigidbody>().AddForce(direction * Random.Range(50, 100)); 
                    justDropped.transform.localScale += new Vector3(newScale, newScale, newScale);


                    return; //remove this for more items

I get gameobjects with scales that are 1 , 1 , 1 as giant items and they don’t transform over time, and for some items who have scale that is more than 1, 1, 1 just come out normal size.

I have a YouTube video about this - YouTube it only requires a few lines of code

If you want to scale a gameobject over time, you need to use:

  1. Co-routines, for the “over time” part

  2. and change the Transform.localScale of the object

Check these links:

I recommend tweening libraries for this. I used iTween for a long time but recently discovered and fell in love with DOTween.

These tasks turn into one line of code that don’t have to be hidden in an update:

transform.DOScale(5f, 1f);

Will scale your object to (5f, 5f, 5f) over 1f seconds.

DOTween: DOTween (HOTween v2)