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 mohd-ma · Jun 05, 2014 at 09:50 PM · guitexture

GUI Textures problem

Hello guys , i,m a begginer in games development , please this trouble killed me , and if i solve it i,ll solve a lot of things and troubles i face it and i,ll achieve my wishes :(

i have many GUITexture , (4) to move my tank forward,back,left and right and (1) GUITexture to shoot fire .

how i can click more than one GUITexture and execute them together , the troublie is : when i click on the first GUITexture & second GUITexture together , no one of them will run .

i,ll make this GUITexture As toutch buttons for my game On Android .

My Code :

 if(Input.GetMouseButton(0) && forwardTexture.HitTest(Input.mousePosition)){
 transform.Translate(Vector3.forward * Time.deltaTime*speed);
 
 }
 if(Input.GetMouseButton(0) && BackTexture.HitTest(Input.mousePosition)){
 transform.Translate(Vector3.back * Time.deltaTime*speed);
 
 }
 
 if(Input.GetMouseButton(0) && leftTexture.HitTest(Input.mousePosition)){
 transform.Rotate(0,-Time.deltaTime*RotateL,0);
 
 }
 
 if(Input.GetMouseButton(0) && rightTexture.HitTest(Input.mousePosition)){
 transform.Rotate(0,Time.deltaTime*RotateR,0);
 
 }
 
 (shoot ) < in another script
 
 if(Input.GetMouseButtonDown(0) && ShootTexture.HitTest(Input.mousePosition))
 {
 
 SHooT();
 
 }
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

1 Reply

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by Tekksin · Jun 05, 2014 at 10:55 PM

You have to set up a for loop to recognize all the buttons being touched, as well as the phases of touch that they are in.

So what you would do is apply a script called "TouchButtonLogic" (or whatever) to all of your gui buttons, and in it, just do something like:

 function Update(){
     if(Input.touches.Length <= 0){ //this tells the device there are no touches
         //the controls do nothing.
         //you may want to reference this script in your other scripts, and control everything through booleans.
     }
 
     if(Input.touches.Length >= 1){ //this tells the device that a touch is happening.
         for(var i = 0; i < Input.touchCount; i++){ //this goes through a loop and assigns a number to each subsequent touch.
             var touch : Touch = Input.GetTouch(i);
             if(touch.phase == TouchPhase.Began && guiTexture.HitTest(Input.GetTouch(i).position)){ //this is for when the touch begins
                 //set the appropriate information here.
                 //again, choose to set booleans in this script and then reference to the already documented info you have in other scripts. It's your choice.
             } else if(touch.phase == TouchPhase.Stationary && guiTexture.HitTest(Input.GetTouch(i).position)){
                 //This is what the device will do if the finger is held down, which if you're moving something by holding down a key, it must be activated here.
             }else if(touch.phase == TouchPhase.Ended && guiTexture.HitTest(Input.GetTouch(i).position)){
                 //this is where you tell the device to stop doign whatever you've told it to do in Begin and especiall stationary.
             }
         }
     }
 }


where I added the /commented out information/ be sure to address the object the script is on, but doing something like:

 if(name == "guiTexture Name"){
   //do this code for that button.
 }
 if(name == "Another guiTexture Name"){
   //do this for the other button
 }
 //and so on.


The unity docs is an excellent resource to do what you're trying here: http://docs.unity3d.com/Manual/MobileInput.html

read it over if my comment confused you in some way. It is essentially the same info. Good luck!

Comment
Add comment · Show 3 · Share
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 mohd-ma · Jun 05, 2014 at 11:22 PM 0
Share

thanks a lot dear , but can you make your script compatable with my script and my GUITextures name , because i,m not good of english and program$$anonymous$$g and i cant understand this good :(

avatar image Tekksin · Jun 05, 2014 at 11:39 PM 0
Share
 function Update(){
  if(Input.touches.Length <= 0){ 
    //tell it to do nothing
  }
      
  if(Input.touches.Length >= 1){
   for(var i = 0; i < Input.touchCount; i++){
    var touch : Touch = Input.GetTouch(i);
     if(touch.phase == TouchPhase.Began && guiTexture.HitTest(Input.GetTouch(i).position)){ 
       if(name == leftTexture){
         //put your code here for the left button.
       }
       if(name == rightTexture){
         //put your code here for the right button. "rightTexture" is what you named the guiTexture GameObject.
       }
     } else if(touch.phase == TouchPhase.Stationary && guiTexture.HitTest(Input.GetTouch(i).position)){
    
     }else if(touch.phase == TouchPhase.Ended && guiTexture.HitTest(Input.GetTouch(i).position)){
     
     }
    }
   }
  }


you cannot use "getmousebutton(0)" for multiple touches.

avatar image mohd-ma · Jun 06, 2014 at 12:50 AM 0
Share

A lot of thanks , I,ll try it :*

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

22 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

Related Questions

How to place/add a HD image/picture in background of my game? 0 Answers

GUI Texture on bottom left/right corners 3 Answers

GUI is not staying where it should 1 Answer

GUI.button Texture shows up in Unity but doesn't show on android device. 1 Answer

How to allow user to import image file from drive 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