Combo Script Problem

Hello Unity3D.I have a problem with my combo script.Anytime i put my combo script into my character.My character freezes and is not able to do the combo or anything at all.If anyone knows why this problem occurs.Can anyone please tell me why?(I have been stuck on this for 2 weeks now…)

P.S Heres a script i have been trying to get with

var comboCount : int = 0;
var fireRate : float = 3;
var timer : float = 0;
var emptygo:GameObject;
var recordInput : String = "";
var waitClearSeconds : float = 1;

 
     function Update()
     {
     
     
     
     RecordInput();
     
     waitClearSeconds -= Time.deltatime; 
     
     if(waitClearSeconds < 0f) {
     
     GetCombo();
     Clear();
     }
     else
      waitClearSeconds -= Time.deltaTime; // This is only reduce when it is grater than 0.
     }
     
     
     function RecordInput() {
     
         if (Input.GetKeyDown("p"))
         {
             if (!fired)
             {
                 
                 fired = true;
                 timer = 0.0;
                 comboCount = 1;
                 Debug.Log("I served a punch!");
                 //Do something awesome to deliver a punch!
                 animation.Play("Rex_Demon__Attack_1");
                 recordInput += "p";
				waitClearSeconds = 1; //reset the wait time to avoid clearing too early
                  audio.Play(); //Finally play the audio
    				audio.volume = 50;
    				 emptygo.GetComponent.<Rigidbody>().velocity = emptygo.transform.TransformDirection(Vector3.forward);
    				 emptygo.rigidbody.AddForce(emptygo.transform.forward * 5);
    				
    		
             }
             else
             {
                 
                 fireRate -= Time.deltaTime; 
                 comboCount++;
                 if (comboCount == 2)
              
                 {
                     Debug.Log("I did a combo!");                
                     //Do something awesome for the combo!
                     animation.Play("Rex_Demon__Attack_2");
                     recordInput += "p";
 					 waitClearSeconds = 1f; //reset the wait time to avoid clearing too early
                     
             }
              else
             {
                 comboCount++;
              
                 if (comboCount == 4)

                 {
                     Debug.Log("I did a combo!");                
                     //Do something awesome for the combo!
                     animation.Play("Rex_s_Combo_Finish_2");
                     animation["Rex_s_Combo_Finish_2"].speed= 2;
                     recordInput += "p";
 					 waitClearSeconds = 1f; //reset the wait time to avoid clearing too early
                   
             }         
              else
             {
                 comboCount++;
              
            	if (comboCount == 6)
                 
                     Debug.Log("I did a combo!");                
                     //Do something awesome for the combo!
                     animation.Play("Rex_Demon__Attack_3");
                     GetCombo();
                     
             }     
  				
                                                 
                 }
             }
         }
         
         
         if (fired)
         {
             timer += Time.deltaTime;
             if (timer > fireRate)
             {
                 comboCount = 0;
                 fired = false;
                 
             }        
         }
     }
     
    function GetCombo() {
 
if((Input.GetKeyDown("k")&&recordInput == "ppp")) 
{
animation.Play("Spinning_Slashes");
waitClearSeconds = 1f; //reset the wait time to avoid clearing too early
	}
}
function Clear() {
recordInput = "";
 
 }

hello @IKilledKenny_2,

Your script:

 function Update() {
  waitClearSeconds -= Time.deltaTime; // this is called every time so waitClearSeconds is become negative.
  
  if(waitClearSeconds < 0f) {
  RecordInput();
  Clear();
                      }
  }

changed Script
function Update()
{

   if(waitClearSeconds < 0f) {
     RecordInput();
     Clear(); // Why use this.
   }
   else
   {
     waitClearSeconds -= Time.deltaTime; // This is only reduce when it is grater than 0.
   }
 }

And you use if wrong way.
you use
if(condition); //if you put semicolon at the end of if condition it will not do any thing if it true or false.

Edited:

Here is a code you might want.
I use switch case for detect keypress for combo. and this might be not best way to do this.
Tell me if you don’t understand any thing in this code. (I didn’t tested it. but you get basic idea from this.)

#pragma strict
var recordInput : String = “”;
var waitClearSeconds : float = 2; //wait 1 second after the last input before clear, you will have to adjust this setting later
var waitToDetectKeyPressTimeSeconds : float = 1; //This is smaller than waitClearSeconds.if waitToDetectKeyPressTimeSeconds == 1 and player press “k” at 10Sec and player press “k” again at 10.3Sec it will not detect it is only detect after 11Sec(10 +waitToDetectKeyPressTimeSeconds).

  function Update()
  {
  
    if(waitToDetectKeyPressTimeSeconds < 0f)
    {
        RecordInput();                  
    }
    else
    {
        waitToDetectKeyPressTimeSeconds -= Time.deltaTime; 
    }
  }
   
     
  function RecordInput() 
  {
      if(Input.GetKeyDown(KeyCode.K))
      {
	      switch (recordInput)
	      {
	      case "":		
		      recordInput = "k";
		      animation.Play("Rex_Sword_Kick");
		      CancelInvoke("ClearKeyPressRecord");
		      Invoke("ClearKeyPressRecord",waitClearSeconds);
		      waitToDetectKeyPressTimeSeconds =1;
		      break;
	      case "k":
		      recordInput = "kk";
		      animation.Play("Rex_Sword_Kick_2");
		      CancelInvoke("ClearKeyPressRecord");
		      Invoke("ClearKeyPressRecord",waitClearSeconds);
		      waitToDetectKeyPressTimeSeconds =1;
		      break;		      
	      case "kk":
		      recordInput = "kkk";
		      animation.Play("Rex_Seal_Combo");
		      CancelInvoke("ClearKeyPressRecord");
		      Invoke("ClearKeyPressRecord",waitClearSeconds);
		      waitToDetectKeyPressTimeSeconds =1;
		      break;
	      case "pp": // if player is press first two time p key and than press k key for combo.
		      recordInput = "ppk";
		      animation.Play("Combo_ppk");
		      CancelInvoke("ClearKeyPressRecord");
		      Invoke("ClearKeyPressRecord",waitClearSeconds);
		      waitToDetectKeyPressTimeSeconds =1;
		      break;			      
	      }
      }
      
      if(Input.GetKeyDown(KeyCode.P))
      {
	      switch (recordInput)
	      {
	      case "":		
		      recordInput = "p";
		      animation.Play("Simple_First_Punch"); //I think p is for punch
		      CancelInvoke("ClearKeyPressRecord");
		      Invoke("ClearKeyPressRecord",waitClearSeconds);
		      waitToDetectKeyPressTimeSeconds =1;
		      break;
	      case "p":
		      recordInput = "pp";
		      animation.Play("Combo_Second_Punch");
		      CancelInvoke("ClearKeyPressRecord");
		      Invoke("ClearKeyPressRecord",waitClearSeconds);
		      waitToDetectKeyPressTimeSeconds =1;
		      break;		      
	      case "pp":
		      recordInput = "ppp";
		      animation.Play("Combo_Third_Punch");
		      CancelInvoke("ClearKeyPressRecord");
		      Invoke("ClearKeyPressRecord",waitClearSeconds);
		      waitToDetectKeyPressTimeSeconds =1;
		      break;
	      case "ppp": 
		      recordInput = "pppp";
		      animation.Play("Combo_pppp");
		      CancelInvoke("ClearKeyPressRecord");
		      Invoke("ClearKeyPressRecord",waitClearSeconds);
		      waitToDetectKeyPressTimeSeconds =1;
		      break;			      
	      case "kkk": 
		      recordInput = "kkkp"; 
		      animation.Play("Spinning_Slashes");
		      CancelInvoke("ClearKeyPressRecord");
		      Invoke("ClearKeyPressRecord",waitClearSeconds);
		      waitToDetectKeyPressTimeSeconds =1;
		      break;
	      }
      }	      
 }

   function ClearKeyPressRecord() 
     {
     recordInput = "";
      
      }