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 11, 2014 at 01:04 PM · iostouchgetcomponentmoveguitexture

move a gameobject from a GUITexture

I really hope someone can help me in this since I am working already two days but without any result. I did post a question here and got some answers, I amend consequentially my original script but still nothing. I'm stuck for days now and I hope someone answer me.

What I' am trying to achieve in this instance is to move a GameObject when a GUI Texture is touch on a Iphone. The GameObject to be moved is named Cube. The Cube has a Script named "Left" that supposedly when is "call it " from the GUITexture the Cube should move left.

I hope is clear: I want to "activated" the script in the Game Object from the Guitexture. I try to use send message but without any joy as well so I am using GetComponent.

This is the script "inside" the GUITexture using C#

public GameObject Cube;

//script inside the gameobject cube so it can move left when call it from the GUItexture

 public Left left; 

     
     void Awake()

 { 
     left = Cube.GetComponent<Left> ();
 }
     
     void Start() 
 { 

 }
     
     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;

                     
                 }
                 
                     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> ();
                      }
                     
          }
                         
     }
 }

}

this is the script named Left inside the game object that get"s activated with GetComponent from the GuiTexture

void Start () {

 }
 
 // Update is called once per frame

         

    void OnMousedown ()
     {
          
              transform.position += Vector3.left * Time.deltaTime;
         

} }

I did search in all videos on you tube, all documentation, all answers and question in stack flow and here

May you please someone help me

I really don't know where is the mistake

Thanks

CL

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

21 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

Related Questions

TWO GUI texture that doesn't work together 0 Answers

Tap to Move Drag to Look Null Reference 1 Answer

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


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