- Home /
              This post has been wikified, any user with enough reputation can edit it. 
            
 
             
               Question by 
               rangkok · Dec 30, 2013 at 01:18 PM · 
                androidiosguitexture2d-gameplay  
              
 
              [C#] guitexture as button for player move on iOS/android
i can't make my player move to right when i touch the button this my script: MY TOUCH LOGIC
 using UnityEngine;
 using System.Collections;
 
 public class TouchLogic : MonoBehaviour {
     
     public static int currtouch = 0;//make other script know what touch currently on screen
     
     void Update()
     {
         if(Input.touches.Length <= 0)
         {
             
         }
         else
         {
             for( int i = 0;  i < Input.touchCount; i++)
             {
                 currtouch = i;
                 Debug.Log(currtouch);
                 
                 if(this.guiTexture != null && (this.guiTexture.HitTest(Input.GetTouch(i).position)))
                 {
                     if(Input.GetTouch(i).phase == TouchPhase.Began)
                     {
                         this.SendMessage("Thit");
                     }
                     if(Input.GetTouch(i).phase == TouchPhase.Ended)
                     {
                         this.SendMessage("Tend");
                     }
                     if(Input.GetTouch(i).phase == TouchPhase.Moved)
                     {
                         this.SendMessage("Tmove");
                     }
                 }
                 
             }
         }
     }
 }
 
 AND MY PLAYER:
 using UnityEngine;
 using System.Collections;
 
 public class player : TouchLogic {
     public GUITexture guit = null;
     public float speedplayer = 5f;
     bool Touch = true;
     
   void Thit() {
         if(guit == Touch)
         {
 
             transform.Translate (Vector3.right * speedplayer * Time.smoothDeltaTime);
         }
     }
 }
 
               Comment
              
 
               
              Answer by MagicoCreator · Dec 30, 2013 at 01:46 PM
you could try unity's built in solution
http://docs.unity3d.com/Documentation/ScriptReference/GUI.RepeatButton.html
 var btnTexture : Texture;
     function OnGUI() {
         if (!btnTexture) {
             Debug.LogError("Please assign a texture on the inspector");
             return;
         }
         if (GUI.RepeatButton(Rect(10,10,50,50),btnTexture)){
             // move your player here;
         }
         
that not compatible for touch in android/ios, thats not allow other touch on the screen.. sorry i forgot to mention it...
Your answer
 
 
              koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                