Increase and decrease localScale once over

Okay so I have an object the pulsing in size over time, But I just want it to pulse up and down once over

    var phi : float = Time.time / duration * 2 * Mathf.PI;
    var amplitude : float = Mathf.Cos( phi ) * 0.5 + 0.5;
    transform.localScale = Vector3(amplitude,amplitude,amplitude);

Any suggestions, Thanks - C

If I understand your question correct, you are looking for a way to make your object go up and down in size once, right?

Take a look at how Sinus/Cosinus is related:

All you need it so figure out where to start and end with the phi value.

instead of Time.time that keeps running, change this value into your own float.

Update with example showing how Sinus works:

	float result = 0f;
	
	for (float deg = 0.0f; deg < 360.0f ; deg +=5f)
	{
		result = Mathf.Sin( deg * Mathf.Deg2Rad ) ;
		
		Debug.Log("Degrees (" +  deg + ") = " + Mathf.Round ( result *1000 )/1000 );
	}

I count from 0 to 360 (a full circle) as you might see 90 degress, 180 degress and 270 are very interesting for your value.

Now, take the function and multiply it result that goes from 0 to 1 and back with your scale size. That value you can use instead of amplitude.

The main observations are (very easy trig and algebra):

1) to get one pulse, run for either 180 or 360 degrees, instead of all the time.

2) depending starting angle, you could go down/up, up/down, snap up then go down, ... so pick the starting angle correctly, using a sin/cos chart.

3) cos/sin thinks 0 degrees is aimed to the right, and goes counter-clockwise in radians. There are 2*PI radians (6.28) in a circle. If you try to use 0-360, you get crazy fast spins. Other things in Unity use degrees and 0 is up, but cos/sin uses "real" math.

4) Sin/Cos go between -1 and 1. `Mathf.Cos( phi ) * 0.5 + 0.5;` (from your code snippet,) scales/slides the range to go from 0 to 1. If you used *2+3, it would go from 1 to 5. The + is the center and the * is the amount +/- it moves.

This C# code worked for me:

// globals:
float growEndSecs = 0;
float GROW_TOTAL_SECS = 2.0f;

// sample line to test:
if(Input.GetKeyDown("z"))
  growEndSecs = Time.time + GROW_TOTAL_SECS; // do this to start growing

// are we currently growing?
if(Time.time < growEndSecs) {
  // pct goes from 0 to 1:
  float pct = 1 - (growEndSecs - Time.time)/GROW_TOTAL_SECS;
  // scale to start ang at -90 (-PI/2), so sin starts at lowest value and goes up:
  float ang = pct * 2*Mathf.PI - Mathf.PI/2.0f;
  // Sin(ang) goes from -1 to 1 back down to -1. Scale to go from 1 to 2 to 1:
  float scaleFact = Mathf.Sin(ang) * 0.5f + 1.5f;
  // NOTE: this ranges from 1.5 +/- 0.5, so 1 to 2
  //       to get 1 to 3, for example, use *1+2
  transform.localScale = Vector3.one * scaleFact;
}