- Home /
 
 
               Question by 
               Griffo · Nov 06, 2012 at 09:18 PM · 
                guitexture2donguidrawtexturemathf.lerp  
              
 
              Mathf.Lerp
How would i write this to lerp only when check is true, as it is Time.time is executed straight away.
 function OnGUI(){
     
 if(check){
 
     GUI.DrawTexture(Rect(Screen.width/2, Screen.height/2, Mathf.Lerp(200, 50, Time.time), Mathf.Lerp(200, 50, Time.time)), MyTexture);
     }
 }
 
              
               Comment
              
 
               
               
               Best Answer 
              
 
              Answer by Xathereal · Nov 06, 2012 at 10:09 PM
You could create your own timer and use Time.deltaTime
 var timer;
 
 function OnGUI(){
 
     if (check == true)
     {
         timer += Time.deltaTime;
         GUI.DrawTexture(Rect(Screen.width/2, Screen.height/2, Mathf.Lerp(200, 50, timer), Mathf.Lerp(200, 50, timer)), MyTexture);
     }
 }
 
              Answer by Griffo · Nov 07, 2012 at 10:38 AM
Xathereal, thanks, you pointed me in the right direction.
 var timer : float;
 var startTime : float;
 var check : boolean;
 var MyTexture : Texture2D;
 
 function Start(){
 
     startTime = 0; // Set to 0 for Lerp to work, between 0 and 1
 }
 
 function Update(){
 
 }
 
 function OnGUI(){
 
     if (check)
     {
         timer = startTime += Time.deltaTime;
 
         GUI.DrawTexture(Rect(Screen.width/2, Screen.height/2, Mathf.Lerp(200, 50, timer), Mathf.Lerp(200, 50, timer)), MyTexture);
     }
 }
 
              Your answer