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