- Home /
 
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
Your answer