Perform action If Input is done in this time.
For my fighting game I want my character to run if my input float is equal to 1 or -1 within 5 frames, and walk if the timer is greater than 5 frames. It sounds easy to pull off, but I can't figure it out somehow.
Here is a little C# sample`if(InputH == 1 || InputH == -1 && timer <= 5.0f){ run = true; transform.Translate(0,0,runH); }`
This might be incorrect, but if anyone knows how, please don't hesitate to reply. Thanks!
Answer by pankajb · May 14, 2016 at 08:42 PM
I am on my mobile so sorry for bad formatting
You can either do
 if( ( inputH == 1 || inputH == -1) && ( timer<=5.0f))
         // run code goes here 
Or
 if( inputH == 1 || inputH == -1)
 {
 if(timer <= 5.0f) 
 // run
 else
 //walk
 }
Answer by SMJMoloney · May 14, 2016 at 08:43 PM
Because the Update function is called once per frame, I believe we can do something simple like this
 using UnityEngine;
 using System.Collections;
 
 public class FrameCount : MonoBehaviour {
 
     int frameCounter = 0;
 
     // Update is called once per frame
     void Update () {
 
         if (Input.GetKeyDown(KeyCode.E))
         {
             frameCounter = 0;
         }
 
         if (frameCounter < 5)
         {
             frameCounter++;
             print(frameCounter);
 
             if (Input.GetKeyDown(KeyCode.F))
             {
                 // Perform Action
             }
 
         }
         else
         {
             // Walk
         }
     }
 }
This will effectively check how many frames have passed since the input. I wouldn't be sure now how to suit it for your system but I imagine you get the gist.
Your answer
 
 
              koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                