transform local Scale problem

Hi,
I am trying to scale an object with reference to its parent’s position in z axis. its works when i use the transform.localScale += new vector3 … But it increases and decreses infinitely. So I tried using mathf.clamp to clamp the values. Its not working though. ANy tips on how to do it? the code goes like this:

public class flameController : MonoBehaviour 
{
	public GameObject player;
	private float zVal, minVal = 1.0f, maxVal = 1.25f;
	private Vector3 termVal;

	void Update()
	{
		zVal = player.transform.position.z;
		print (zVal);
		termVal = new Vector3 (0, 0, Mathf.Clamp(transform.localScale.z, minVal, maxVal));
		if (zVal >= 1.0f)
		{
			transform.localScale = termVal; 
		}
	}
}

Probably using this

if (zVal > 1.0f)

instead of

if (zVal >= 1.0f)

will solve you issue?

I dont think so… I need to know some logic to over come

transform.localScale += termVal; , which scales my object in z axis indefinitely. That is why i have used the clamp which fails my purpose now. the if condition acts just a trigger.

This line adds your scale value on every update, Of course it will scale indefinitely.

Your problem is this line:

termVal = new Vector3 (0, 0, Mathf.Clamp(transform.localScale.z, minVal, maxVal));

This scales the object to nothing on the x and y axis.
Use the original scale values instead.

Yes I found it out and gave the actual values in x and y. Now is there any way that i scale it in z axis with reference to the parent object position.z ?