Advertisement
GoodNoodle

Button Mash.cs

Sep 10th, 2023 (edited)
1,000
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.60 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using Unity.VisualScripting;
  4. using UnityEngine;
  5.  
  6. public class ButtonMash : MonoBehaviour
  7. {
  8.  
  9.  
  10.  
  11.    public int mash;
  12.  
  13.     public float countdown = .5f;
  14.  
  15.    bool iscounting;
  16.  
  17.    public bool pressed;
  18.  
  19.    public bool mashStart;
  20.  
  21.     public GameObject testSprite;
  22.     // Start is called before the first frame update
  23.     void Start()
  24.     {
  25.        
  26.     }
  27.  
  28.     // Update is called once per frame
  29.     void Update()
  30.     {
  31.         if (iscounting)
  32.         {
  33.             if (countdown >= 0)
  34.             {
  35.  
  36.                 countdown -= Time.deltaTime;
  37.             } else
  38.             {
  39.                 iscounting = false;
  40.             }
  41.         }
  42.  
  43.  
  44.         if (countdown <= 0)
  45.         {
  46.             mash--;
  47.             countdown = .5f;
  48.         }
  49.  
  50.         if (Input.GetKeyDown(KeyCode.Space))
  51.         {
  52.             mashStart = true;
  53.  
  54.         }
  55.         if (mashStart)
  56.         {
  57.          
  58.             testSprite.SetActive(true);
  59.            
  60.             if (Input.GetKeyDown(KeyCode.Space) && !pressed)
  61.             {
  62.            
  63.                 pressed = true;
  64.                 mash++;
  65.              
  66.             }
  67.             else if (Input.GetKeyUp(KeyCode.Space))
  68.  
  69.             {
  70.                 iscounting = true;
  71.  
  72.                 pressed = false;
  73.  
  74.                  
  75.             }
  76.             if (mash <= 0)
  77.             {
  78.                 mash = 0;
  79.                 iscounting = false;
  80.                 mashStart = false;
  81.                 testSprite.SetActive(false);
  82.             }
  83.         }
  84.     }
  85.  
  86.    
  87. }
  88.  
  89.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement