- Home /
Question by
yaezah · Sep 18, 2017 at 09:50 PM ·
transformscalelocalscaletime.time
How to make an object's localscale values grow and shrink within a few seconds?
I'm trying to make this 2D sprite pulsate from small to big within 2 seconds. I've went through a few Unity questions and the closest one that works is this:
public float amplitude;
public Vector3 scale;
void Start()
{
AudioControl.Instance.spin();
Destroy(gameObject, 2.5f);
}
// Update is called once per frame
void Update () {
for (int i = 0; i < 3; ++i)
{
scale[i] = amplitude * Mathf.Sin(Time.time) + 1;
}
transform.localScale = scale;
}
}
The problem with this script is that is it going by Time.time and every time the object is instantiated it's not starting off from localScale 1 , but continuing from the same position as the others .
Comment
How about saving the current Time.time when starting and subtracting it? This way no matter what, the algorithm starts at time 0.