Hey there.
So I've got this Movement/Action-Script which is attached to all my four UIImage-Buttons. They are seperated in four different states and do their job well.
using UnityEngine;
using System.Collections;
public class TestButton : MonoBehaviour
{
public ButtonType type;
public NGUIInput input;
public RaycastCharacterController controller;
public tk2dAnimatedSprite playerSprite;
public SpriteAnimator animator;
public GameObject weapon;
private bool attacking = false;
void HitCompleteDelegate (tk2dAnimatedSprite sprite, int clipId)
{
if (!playerSprite.IsPlaying ("attack")) {
weapon.active = false;
}
if (!attacking) {
CheckDirectionIdle ();
playerSprite.Play ("idle");
}
if (animator.jumping) {
playerSprite.Play ("jump");
}
if (animator.walking) {
playerSprite.Play ("walk");
}
}
void Start ()
{
weapon.active = false;
}
void Update ()
{
if (playerSprite.IsPlaying ("jump"))
CheckDirectionIdle ();
}
public void OnPress (bool pressed)
{
if (pressed) {
switch (type) {
case ButtonType.LEFT :
input.SetX (-1f);
weapon.active = false;
playerSprite.animationCompleteDelegate = HitCompleteDelegate;
if (playerSprite.IsPlaying ("attack"))
playerSprite.Stop ();
animator.walking = true;
break;
case ButtonType.RIGHT :
input.SetX (1f);
weapon.active = false;
playerSprite.animationCompleteDelegate = HitCompleteDelegate;
if (playerSprite.IsPlaying ("attack"))
playerSprite.Stop ();
animator.walking = true;
break;
case ButtonType.JUMP :
input.Jump (true);
weapon.active = false;
playerSprite.animationCompleteDelegate = null;
break;
case ButtonType.ATTACK :
if (!playerSprite.IsPlaying ("attack")) {
playerSprite.Play ("attack");
weapon.active = true;
attacking = true;
playerSprite.animationCompleteDelegate = HitCompleteDelegate;
CheckDirectionAttack ();
}
attacking = false;
break;
}
} else {
switch (type) {
case ButtonType.LEFT :
input.SetX (0.0f);
weapon.active = false;
break;
case ButtonType.RIGHT :
input.SetX (0.0f);
weapon.active = false;
break;
case ButtonType.JUMP :
input.Jump (false);
weapon.active = false;
break;
case ButtonType.ATTACK :
input.SetX (input.x);
weapon.active = false;
break;
}
}
}
public enum ButtonType
{
LEFT,
RIGHT,
JUMP,
ATTACK,
};
The Problem is the JUMP-Part.
When I press that Button the Character is jumping. Fine. But when I press and HOLD it, the Character is jumping all the time with no change in other States, and of course the Animation is "stuck" in the last frame of the Jump-Animation. What do I want to do:
Is there a way to stop or disable the input of nGUI, meaning: the Player presses and HOLDS the Button, the Character jumps BUT stays grounded after that and the Player has to release the Button and press again.
Thanks in Advance for the Answers
