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 Shory90 · Jan 15, 2014 at 12:03 AM · c#inputtouch

Help changing mouse input to touch input.

This script works fine but I cannot understand how to make it work with touch input. I have read and watched tutorials, but I cannot seem to get it done. Could someone change this script to touch so I can get forward with learning and with my project. Thank you in advance.

 using UnityEngine;
 using System.Collections;
     
     public class PauseMenu : MonoBehaviour 
     {
         private bool PopUp;
         public bool pause_button = false;
         public bool resume_game = false;
         public bool quit_to_menu = false;
         public bool    standard = false;
         public bool    scroll = false;
         public bool time_trial = false;
         public bool quitgame = false;
         public bool upgrades = false;
         
         void OnMouseDown()
             {
             if(standard)
                 {
                 StartGame.Lvl = 1;
                 GameObject Sphere = GameObject.Find("Sphere");
                 Sphere.rigidbody.isKinematic = false;
                 Sphere.rigidbody.AddForce(0f, 600f, 0f);
                 }
             
             if(scroll)
                 {
                 StartGame.Lvl = 2;
                 GameObject.Find("Sphere").rigidbody.isKinematic = false;
                 GameObject.Find("Sphere").rigidbody.AddForce(0f, 600, 0f);
                 }
             
             if(time_trial)
                 {
                 StartGame.Lvl = 3;
                 GameObject Sphere = GameObject.Find("Sphere");
                 Sphere.rigidbody.isKinematic = false;
                 Sphere.rigidbody.AddForce(0f, 600, 0f);
                 }
             
             if(upgrades)
                 {
                 
                 GameObject Cam =  GameObject.Find("!Camera");
                 Cam.animation.Play("CameraLaptop");
                  GameObject.Find("Laptop/Static").renderer.enabled = false;
                 StartCoroutine(Up_Delay());
                 }        
             
             if(quitgame)
                 PopUp = true;
             
             if(pause_button)
                 {
                 Time.timeScale = 0.00001f;
                 GameObject Pausemenu = GameObject.Find("PauseMenu");
                 foreach(Transform child in Pausemenu.transform)
                         child.gameObject.SetActive(true);
                 GameObject PU =  GameObject.Find("PowerUps");
                 foreach(Transform child in PU.transform)
                         child.gameObject.SetActive(false);
                 
                 }
             
             if(resume_game)
                 {
                 
                 GameObject.Find("Sphere").AddComponent<Resume>();
                 GameObject Pausemenu = GameObject.Find("PauseMenu");
                     foreach(Transform child in Pausemenu.transform)
                         child.gameObject.SetActive(false);
                 GameObject PU =  GameObject.Find("PowerUps");
                 foreach(Transform child in PU.transform)
                     child.gameObject.SetActive(true);
                 }
             
             if(quit_to_menu)
                 {
                 Time.timeScale = 1;
                 Application.LoadLevel(0);
                 }
             }
             
         void DrawInfo()
         {
               Rect rect = new Rect (300, 225, 350, 150); 
             Rect Yes = new Rect(350, 325, 80, 40);
             Rect No = new Rect(525, 325, 80,40);
             if (PopUp)
                    {
                 GUI.Box(rect, "Do you really want to exit?");
                 if(GUI.Button(Yes, "Yes"))
                     {    
                     PopUp = false;
             
                     StartCoroutine(delay(2.0F));
                     }
                 
                 if(GUI.Button(No, "No"))
                       PopUp = false;
                 
                 }
         }    
         
         void OnGUI()
                 {
             DrawInfo();
             }
         
         IEnumerator delay(float waitTime)
             {
             yield return new WaitForSeconds(waitTime);
             Application.Quit();
             }
         
         IEnumerator Up_Delay()
             {
              yield return new WaitForSeconds(1.11f);
             GameObject.Find("Laptop/Upgrades").renderer.enabled = true;
             GameObject.Find("Laptop/BorderDown").renderer.enabled = true;
             }
             
     }
     
Comment
Add comment · Show 2
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
avatar image robertbu · Jan 15, 2014 at 12:07 AM 0
Share

Have you tried this script on your touch device? On$$anonymous$$ouseDown() will work with touch, though it can cause a performance hit for handheld devices. Note that if you first converted this code to use Raycasting to detect the mouse hit, the movement to touch would be much smaller.

avatar image OP_toss · Jan 15, 2014 at 02:17 AM 0
Share

That or you can explicitly use touch interface code:

 void Update$$anonymous$$ouse()
 {
   if (Input.Get$$anonymous$$ouseDown(0))
   {
     //todo
   }
 }
 
 void UpdateTouch()
 {
   foreach (Touch touch in Input.touches)
   {
     //todo
   }
 }
 
 void FixedUpdate()
 {
   //update whichever based on Application.platform
   // or use compile-time vars
 }

http://docs.unity3d.com/Documentation/ScriptReference/Input-touches.html

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

19 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

Related Questions

Swipe and Hold to move character . 1 Answer

C# Screen.width Touch Input In Multiple Scripts Affect Each Other - Please Help 1 Answer

Mobile game touch problem (C#) 2 Answers

Detect if dragged over object 1 Answer

Get clicked object cords on object ? Unity2D 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