Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by UnityMadDev · May 18, 2015 at 10:35 AM · c#androidguiiosinput

Touch Input with Event Trigger. How to handle with it properly.

Hello Community,

Since this is my first post I wanted to say hello.

As every beginner developer I have a lot of problems. Below one of them:

I wrote simple script to control my 'Player' object:

 using UnityEngine;
 using System.Collections;
 
 public class PlayerMovement : MonoBehaviour {
 
     public float jumpVelocity = 10;
 
     private Transform groundCheck;
     private Animator anim;
     private Rigidbody2D rigidbody2D;
     private bool grounded;
     private Physics2D gravity;
 
     [SerializeField] private LayerMask whatIsGround;
 
     const float groundedRadius = .2f;
 
 
     void Awake () {
 
         // Setting up references.
         groundCheck = transform.Find("GroundCheck");
         anim = GetComponent<Animator>();
         rigidbody2D = GetComponent<Rigidbody2D>();
         
     }
 
     // Use it for Graphic & Input
     void Update () {
         
     }
     
     //Physics and ground check
     void FixedUpdate () {
 
         grounded = false;
 
         Collider2D[] colliders = Physics2D.OverlapCircleAll(groundCheck.position, groundedRadius, whatIsGround);
         for (int i = 0; i < colliders.Length; i++)
         {
             if (colliders[i].gameObject != gameObject)
                 grounded = true;
         }
 
     }
 
     //Jump function
     public void Jump () {
 
         if (grounded) 
             rigidbody2D.velocity = jumpVelocity * Vector2.up;    
     }
 
     //Gliding function
     public void GlideON () {
     
         rigidbody2D.gravityScale = 1;
         Debug.Log ("Graviti is on");
     }
 
     public void GlideOFF () {
 
         rigidbody2D.gravityScale = 0;
         Debug.Log ("Graviti is off");
 
         if (!grounded) {
             rigidbody2D.velocity = ( -jumpVelocity / 10 ) * Vector2.up;
         }
     }
 
 }

To operate touch screen I used GUI function like this:

alt text

What I want to achieve:

  • One click - Player jump

  • Hold button - Player starts glide.

  • Player can not glide when he's grounded.

  • It does not matter whether I start from 'PointerClick' or 'PointerDown'. If player is grounded the first action should be 'Jump' always.

  • If we start with 'PointerDown', Player should jump and after reaching the maximum height he starts glide.

  • If we start with 'PointerClick' Player should jump.

  • If Player is not grounded and we want to start glide - we have to touch screen and hold it.

Where is the problem:

  • When I start with 'PointerDown', my Player begins infinite jump until 'PointerUp'.

I would be grateful for your help and suggestions.

gui.png (60.1 kB)
Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

2 People are following this question.

avatar image avatar image

Related Questions

Store/Stack Items 0 Answers

Button as a child of a button 0 Answers

How can I know when the user slide his finger? 0 Answers

fixed the problem 2 Answers

Android Plugin Help 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges