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 London243 · Jun 12, 2014 at 07:56 PM · iostouchgetcomponentmoveguitexture

TWO GUI texture that doesn't work together

I have two GUITexture that move left and right a cube. Is pretty strange but together they don't work. If I activate only one it works. To be more specific: If I have the left GUItexture alone in the game the cube move left. If I have the right GUITexture activated alone the cube move right. Seems all fine I thought but If I have both of them the cube move only right and not left. Where is the mistake?

Here is the code inside the GameObject cube for Right move

void OnMousedown () {

 transform.position += Vector3.right * Time.deltaTime;


For Left move

void OnMousedown () {

      transform.position += Vector3.left * Time.deltaTime;


And this is the left GUITexture code

               void Update ()
 {
     
     //is there a touch on screen 
     
     if (Input.touches.Length <= 0) 
     {
         //if there is no touches on the screen  the this code
         
         return;
     } 
     
     else // if there is a touch
         
     {
         
         //loop through all the touches on the screen 
         
         for(int i = 0 ; i < Input.touchCount; i++)
         {
             //execute this code for current touch (i) on the screen 
             
             if(this.guiTexture.HitTest(Input.GetTouch(i).position))
             {
                 //if current hits our GUITexture, run this code
                 if(Input.GetTouch (i).phase == TouchPhase.Began)
                     
                     //move the cube
                     
                 Cube.GetComponent<Left>().enabled = true;
                 left.transform.position += Vector3.left * Time.deltaTime;
                 
             }
             
             if(Input.GetTouch (i).phase == TouchPhase.Ended)
                 
             {      
                 
                 return; 
             }
             if(Input.GetTouch(i).phase == TouchPhase.Stationary);
             
             
             //if current finger is stationary  run this code
             {      
                 Cube.GetComponent<Left> ().enabled = true;
                 left.transform.position += Vector3.left * Time.deltaTime

This is the right GUITexture code

       void Update ()
 {
     
     //is there a touch on screen 
     
     if (Input.touches.Length <= 0) 
     {
         //if there is no touches on the screen  the this code
         
         return;
     } 
     
     else // if there is a touch
         
     {
         
         //loop through all the touches on the screen 
         
         for(int i = 0 ; i < Input.touchCount; i++)
         {
             //execute this code for current touch (i) on the screen 
             
             if(this.guiTexture.HitTest(Input.GetTouch(i).position))
             {
                 //if current hits our GUITexture, run this code
                 if(Input.GetTouch (i).phase == TouchPhase.Began)
                     
                     //move the cube
                     
                     Cube.GetComponent<Left>().enabled = true;
                     right.transform.position += Vector3.right * Time.deltaTime;
                 
             }
             
             if(Input.GetTouch (i).phase == TouchPhase.Ended)
                 
             {      
                 
                 return; 
             }
             if(Input.GetTouch(i).phase == TouchPhase.Stationary);
             
             
             //if current finger is stationary  run this code
             {      
                 Cube.GetComponent<Left> ().enabled = true;
                 right.transform.position += Vector3.right * Time.deltaTime;
             }

What is the reason for this? Why they don't work together meaning when I push the left gui texture the cube moves left and when I push the right guitexture the cube move right

I hope someone can help me. I really have no clue and did search all day about this

CL

Comment
Add comment · Show 3
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 London243 · Jun 13, 2014 at 09:09 AM 0
Share

Hello Robertbu, I have included the full code for the the left and right GUItexture. IN theory when I push the GUItexture should move the cube left if I push the left GUITexture and and right if I push the right GUItexture . But as I said they work well only when they are not together meaning only one of them. The script inside the cube named Left and Right was already all of it therefore I didn't updated.any idea why?

avatar image robertbu · Jun 13, 2014 at 02:44 PM 1
Share

I don't see the problem. There is one potential issue. You state you use:

 void On$$anonymous$$ousedown 

But you misspelled the name of the callback. It is On$$anonymous$$ouseDown(), so this callback is not being called. But I'm confused about the use of this function at all. Usually you would only use On$$anonymous$$ouseDown() or HitTest() but not both. But based on your description, this is not the base of your movement problem.

avatar image London243 · Jun 13, 2014 at 03:19 PM 0
Share

Thank you. It made all the difference. Again thank you CL

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

move a gameobject from a GUITexture 0 Answers

How to use the joystick to control the character 3 Answers

Altering Z position of guiTexture through code IOS? 1 Answer

Calling Function in other Script via Touch => iOS Crash 1 Answer

Move Camera Over Terrain Using Touch Input 2 Answers


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