• 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 /
  • Help Room /
avatar image
0
Question by MG-BS-500 · Mar 17, 2016 at 04:28 PM · touchtransform.positiontouchphaseguibuttonfinger

Transform Position - GUI Button

Hi, i have this script:

 using UnityEngine;
 using System.Collections;
  
 public class Test : MonoBehaviour
 {
     public GameObject Player;
     private Vector2 touchPos;
     private bool show = false;
  
     void Start() {
         GUI.enabled = false;
     }
  
     void Update() {
         if (Input.touchCount > 0 && Input.GetTouch (0).phase == TouchPhase.Began) {
             // SHOW BUTTON
             GUI.enabled = true;
             show = !show;
         }
     }
  
     void OnGUI ()
     {
         if (Input.touchCount > 0) {
  
             //TOUCH POSITION
             Touch touch;
             touch = Input.GetTouch (0);
  
             touchPos.x = touch.position.x;
             touchPos.y = Screen.height - touch.position.y;
         }
  
         if (show) {
             // GUI BUTTON POSITION = TOUCH POSITION
      
          if (GUI.Button (new Rect (touchPos.x + 30, touchPos.y + 30, 300, 100), "Teleport")) {
  
                 // TRANSFORM POSITION - HIDE BUTTON
                 Player.transform.position = Camera.main.ScreenToWorldPoint (Input.GetTouch (0).position);
                 GUI.enabled = false;
                 show = !show;
          
             }
         }
     }
 }


With the first touch I decide the position of the button, after finishing the phase of touch the button remains open. With the second touch on the button I decide the position of the player but I have a problem: When I use the touch on the button should be two fingers on the screen otherwise the player position is not changed, how can I make the button work with just one finger ?

Thanks in advance.

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.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

59 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Enable disable Rigidbody 2D when touch phase starts? 0 Answers

Show / Hide GUI Button - Enable / Disable Script (Android) 0 Answers

Unable to use Swipe and Unity UI together 0 Answers

Replace TouchPhase.Ended with booleans? 1 Answer

Hi I'm making a game for Android(2d game). I have to move a ball using the swipe(not just vertical and horizontal). The problem is that the ball is moving in the wrong Y axis and I don't understabd why 0 Answers

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges