Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Problems about Move and Jump use NGUI sprite?

Discussion in '2D' started by Green-Jungle, Sep 16, 2014.

  1. Green-Jungle

    Green-Jungle

    Joined:
    Jun 10, 2014
    Posts:
    79
    Hello everyone.I'm making a game like mario.I'm using sprite of NGUI as the buttons to move and jump.
    I write a class below and attack on JUMP button(sprite of NGUI) below:
    Code (CSharp):
    1.  
    2. bool mHover=false;
    3. void Update(){
    4. if (mHover) {
    5.          
    6.  
    7.          mPlayer.JumpHandler();
    8. }
    9. void OnPress (bool isOver){
    10.      
    11.         mHover = isOver;
    12.  
    13.      
    14.     }
    my problem is:
    If I click too times on button jump(sprite of NGUI) then player jump too taller.how to catch only click a time on button .I don't find get count on OnPress() method of NGUI
    Sorry my English.
     
  2. cbothra

    cbothra

    Joined:
    Mar 14, 2014
    Posts:
    125
    Hi, If you want to achieve this in the current scenario which you've mentioned in the above post, then you shall have a boolean var which gets turned on when the button is clicked for the first time and again reset when your animation is over and you can add a checking related to that boolean var in the OnPress method, that if its turned on than not to listen to any further events.

    Besides that if you shall also have a look at the OnClick method of the NGUI.

    Hope this helps!