Answer the question
In order to leave comments, you need to log in
How to make an object zoom smoothly?
How to make smooth zoom? for example, an object with a size of 1,1,1 touched the trigger and its value changed to 2,2,2. But smoothly from 1,1,1 to 1.2,1.2,1.2 then 1.3 and so on up to 2.
Actually there is an increase code, but it instantly increases from 1 to 2.
using UnityEngine;
using System.Collections;
public class Eat : MonoBehaviour
{
public string Tag;
public float Increase;
void OnTriggerEnter(Collider other)
{
if(other.gameObject.tag == Tag)
{
transform.localScale += new Vector3(Increase, Increase, Increase); // ?
Destroy(other.gameObject);
}
}
}
Answer the question
In order to leave comments, you need to log in
Lerp to Update by time. You remember the current scale and the target one, set the time for how much you need to change, and each frame is interpolated between them.
Or use plugins like tweener.
Option with coroutines. Launch via:
IEnumerator SlowScale()
{
for (float q = 1f; q < 2f; q += .1f;)
{
transform.localScale = new Vector3(q, q, q);
yield return new WaitForSeconds(.05f)
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question