Replace TouchPhase.Ended with booleans?
Hi there, initially I was using TouchPhase.Ended (it is commented out), to addForce to my gameObject after touch has ended and it worker perfectly, but it didn't work on one of my phones (Android 6.0.1 .. so it shouldn't be outdated or anything).
So I am trying to replace TouchPhase.Ended with booleans and whatnot but it's simply not working. Any suggestions? P.S. I'm quite new to this.
void Start () {
Physics.gravity = new Vector3 (0, -20, 0);
rb = GetComponent<Rigidbody>();
}
// Update is called once per frame
void Update () {
float dst = Vector3.Distance (target.position, transform.position);
float shotpower = power * dst * 20;
transform.LookAt (target);
if (Input.touchCount > 0) {
isTouching = true;
if ((Input.GetTouch (0).phase == TouchPhase.Stationary) || (Input.GetTouch (0).phase == TouchPhase.Began)) {
Physics.gravity = Vector3.zero;
rb.velocity = Vector3.zero;
rb.angularVelocity = Vector3.zero;
}
}
if((isTouching) && (Input.touchCount == 0)){
//if (Input.GetTouch (0).phase == TouchPhase.Ended) {
rb.AddForce ((target.position-transform.position) * shotpower);
Physics.gravity = new Vector3 (0, -20, 0);
if(Physics.gravity == new Vector3(0,-20,0)){
isTouching = false;
}
}
Answer by MeowingMammoth · Oct 05, 2017 at 08:32 PM
solution: created a button size of entire screen and instead of using touchinputs i'm using button event triggers
Your answer
Follow this Question
Related Questions
iOS moving up and down question ( code problem ) 0 Answers
Two finger tap causes jump bug 0 Answers
Android Controls 1 Answer
Jump by touch Unity C# 0 Answers
Player follow touch when holding down your finger on the screen (C#) 1 Answer