Smooth scale Object every second
Hey guys! What is the best way to make a smooth transission between changing scale values? I have a setup where every second i get a new value from my arduino board. I want to use this value to scale my box in every direction. Scaling by the values is fine, but theres no smooth transission between one scale and the other. Do you know how this could work and pllleeeeeaaaassseee can you give me an example? Here is the code i have so far: using System.Collections; using System.Collections.Generic; using UnityEngine; using System.IO.Ports;
public class ScaleSmoothNEU : MonoBehaviour
{
SerialPort sp = new SerialPort("COM3", 9600);
// Use this for initialization
void Start()
{
sp.Open();
}
// Update is called once per frame
void Update()
{
if (!sp.IsOpen)
sp.Open();
double a = int.Parse(sp.ReadLine());
double speedScale = 1.0F;
Vector3 actualScale = transform.localScale;
Vector3 targetScale = Vector3.one * ((float)(a / 10));
transform.localScale = Vector3.Lerp(actualScale, targetScale, ((float)(speedScale) * Time.deltaTime));
}
}
Thanks!
Answer by tormentoarmagedoom · Oct 18, 2018 at 10:56 AM
Good day.
I did not read all your post, but for..
"What is the best way to make a smooth transission between changing scale values? "
Animation is a very good solution.
The other way is to use a corutine to control timing of reduce the scale with something like
object.transform.scale -= new Vector3 (0.1, 0.1, 0.1);
Or something like this...
Or simply use Lerp function to smooth it
Bye!
Your answer
Follow this Question
Related Questions
Getting the complete size of the children and setting that to parent's size 0 Answers
Player position relative to rotating platform [gif included] 0 Answers
Saving default scale of an object c# 1 Answer
Player Prefab scale automatically goes to 1 x 1 x 1 whereas I have set it to 0.48 x 0.48 x 0.48 1 Answer
Content Size Fitter should scale only in one direction 0 Answers