- Home /
Android game character continuous movement when touching screen ends,android game character continuous movement when touching screen ends
in my game the first time player touches the screen a bridge scales upwards and when the player end touching screen the bridge falls to the ground so the character can automatically move to the next location, it works fine when i use keyboard keys to do this but for touch the character teleports a bit forward and then stops there also when i build the game for android and install the apk file the game is laggy and physics are broken the character gets stuck when it is moving away from a box collider.
here's the code :
 using System.Collections;
 using System.Collections.Generic;
 using System.Threading;
 using UnityEngine;
 using UnityEngine.UI;
 
 public class polgrowth : MonoBehaviour
 {
     public float boot = 0;
     public bool move = true;
     public Button button;
     public GameObject polgrowthobj;
     public Animator animfold;
     float growthspeed = 0.1f;
     Vector3 temp;
     int Status = 0;
     string toastString;
     public bool joon = false;
 
     public Transform player5;
     public Animator run;
     public float moveSpeed2;
 
     AndroidJavaObject currentActivity;
 
     // Start is called before the first frame update
     void Start()
     {
         polgrowthobj.GetComponent<polgrowth>();
     }
     void showToastOnUiThread(string toastString)
     {
         AndroidJavaClass UnityPlayer = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
         currentActivity = UnityPlayer.GetStatic<AndroidJavaObject>("currentActivity");
         this.toastString = toastString;
         currentActivity.Call("runOnUiThread", new AndroidJavaRunnable(showToast));
     }
     void showToast()
     {
         AndroidJavaObject context = currentActivity.Call<AndroidJavaObject>("getApplicationContext");
         AndroidJavaClass Toast = new AndroidJavaClass("android.widget.Toast");
         AndroidJavaObject javaString = new AndroidJavaObject("java.lang.String", toastString);
         AndroidJavaObject toast = Toast.CallStatic<AndroidJavaObject>("makeText", context, javaString, Toast.GetStatic<int>("LENGTH_LONG"));
         toast.Call("show");
     }
     // Update is called once per frame
     void FixedUpdate()
     {
         if (move)
         {
             temp = transform.localScale;
             if (Input.GetKey(KeyCode.Alpha5))
             {
                 temp.y += 1f;
                 transform.localScale = temp;
             }
             if (Input.GetKeyUp(KeyCode.Alpha5))
             {
                 animfold.Play("fold");
                 polgrowthobj.GetComponent<polgrowth>().enabled = false;
                 moveSpeed2 = 3f;
                 player5.Translate(Vector3.forward * Time.deltaTime * moveSpeed2);
             }
             if (Input.touchCount > 0)
             {
                 Touch touch = Input.GetTouch(0);
                 if (touch.phase == TouchPhase.Stationary)
                 {
                     temp.y += 1f;
                     transform.localScale = temp;
                     Status = 1;
                     if (Application.platform == RuntimePlatform.Android)
                     {
                         showToastOnUiThread(Status.ToString());
                     }
                     if (touch.phase == TouchPhase.Ended)
                     {
                         animfold.Play("fold");
                         polgrowthobj.GetComponent<polgrowth>().enabled = false;
                     }
                     if (touch.phase == TouchPhase.Moved)
                     {
                         boot++;
                     }
                     if (boot > 0)
                     {
                         moveSpeed2 = 3f;
                         player5.Translate(Vector3.forward * Time.deltaTime * moveSpeed2);
                     }
                 }
             }
         }
     }
 }
 
Your answer
 
 
             Follow this Question
Related Questions
swipe movement script like in subway surfer 0 Answers
Why does collision detection work in editor but not in android build? (Ar foundation) 0 Answers
physics.gravity with tilt game 1 Answer
Physics on a Ball 1 Answer
Sometimes the ball isn't moving 0 Answers
 koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                