Near Clipping changing problem about time

Hello everyone, I have a problem. I simply want to make my camera’s near clipping plane after it has finished aiming. I was following ETeeski’s tutorials and got this line of code to aim :

if (Input.GetButton("Fire2")){
	
		racioHipHold = Mathf.SmoothDamp(racioHipHold, 0, racioHipHoldV, hipToAimSpeed);		

}

now that line makes it to aim, it’s OK. Now I want to change the near clipping planeso the gun would be invisible and I tried this :

if (Input.GetButton("Fire2")){
	
		racioHipHold = Mathf.SmoothDamp(racioHipHold, 0, racioHipHoldV, hipToAimSpeed);		
cameraObject.camera.nearClipPlane = 2;
}

it works but the problem is it makes nearClipPlane = 2 as soon as I click to Fire2 button. I don’t want that I just want to make it to change nearClipPlane after the first line of code, which is about aiming finished. I tried courutine but it causes other problems. Any ideas ?

Perhaps you could check how much time has passed. I’m guessing hipToAimSpeed is a float? If it is then you could try subtracting time from that number and checking if it’s null :

var TimerCount : boolean = false;
var Timer : float;

function Start () {
  Timer = hipToAimSpeed;
}

function Update () {

  if (Input.GetButton("Fire2")){

       racioHipHold = Mathf.SmoothDamp(racioHipHold, 0, racioHipHoldV, hipToAimSpeed);     
       TimerCount = true;
  }



 if(TimerCount)
 {
  if(Timer <= 0)
  {

  cameraObject.camera.nearClipPlane = 2;
  TimerCount = false;
  Timer = hipToAimSpeed;

  } else {

  Timer -= Time.deltaTime;

  }
 }

}