Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using Unity.VisualScripting;
- using UnityEngine;
- public class ButtonMash : MonoBehaviour
- {
- public int mash;
- public float countdown = .5f;
- bool iscounting;
- public bool pressed;
- public bool mashStart;
- public GameObject testSprite;
- // Start is called before the first frame update
- void Start()
- {
- }
- // Update is called once per frame
- void Update()
- {
- if (iscounting)
- {
- if (countdown >= 0)
- {
- countdown -= Time.deltaTime;
- } else
- {
- iscounting = false;
- }
- }
- if (countdown <= 0)
- {
- mash--;
- countdown = .5f;
- }
- if (Input.GetKeyDown(KeyCode.Space))
- {
- mashStart = true;
- }
- if (mashStart)
- {
- testSprite.SetActive(true);
- if (Input.GetKeyDown(KeyCode.Space) && !pressed)
- {
- pressed = true;
- mash++;
- }
- else if (Input.GetKeyUp(KeyCode.Space))
- {
- iscounting = true;
- pressed = false;
- }
- if (mash <= 0)
- {
- mash = 0;
- iscounting = false;
- mashStart = false;
- testSprite.SetActive(false);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement