mardi 26 décembre 2017

Cant Detect if mouse button is held or just tapped once

Well i made a bunny that teleports on tap and i want to make it so if you hold for more than 0.3f a bubble activates and protects it i tried multiple code variates but i cant get it to work in some situation the bunny teleports and activates the bubble after and in others it doesnt i know its something simple and i just have to adjust the if / else if so i will be thankfull for eny help

using UnityEngine;
using System.Collections;

public class tap : MonoBehaviour {
// Use this for initialization
public GameObject Bunny;
public GameObject BunnyUpEffect;
public GameObject BunnyDownEffect;
public static bool IsHeld = false;
float TimeHeld = 0f; 
void Start () {
}

// Update is called once per frame
void Update () {

    if (Input.GetMouseButton (0)) {
        TimeHeld += Time.deltaTime;
        if (TimeHeld > 0.3f) {
            BubbleScript.BubbleActive = true;
            IsHeld = true;
        }
    }

    else {
        BubbleScript.BubbleActive = false;
        IsHeld = false;
        TimeHeld = 0f;
        if (Input.GetMouseButtonDown(0) && IsHeld == false) {

            if (BunnyScript.BunnyAlive == true) {
                if (BunnyScript.RunBottom == true) {
                    if (Stats.Energy > 0) {
                        BunnyUpEffect.GetComponent<BunnyUpEffect> ().Up ();
                    }
                } else if (BunnyScript.RunBottom == false) {
                    BunnyDownEffect.GetComponent<BunnyDownEffect> ().Down ();
                }
                Bunny.GetComponent<BunnyScript> ().ChangePos ();
            }
    }
}
}
}

Aucun commentaire:

Enregistrer un commentaire