Hey im experimenting something on mobile phones but it won’t work.My point that i want to achieve is when i tap the screen the object to reverse gravity and when i tap it again to bring back normal gravity.My issue is that when i tap the second time it won’t bring back normal gravity .Here is my code:
using UnityEngine;
using System.Collections;
public class pControls : MonoBehaviour {
public GameObject pb=null;
Rigidbody2D p;
void Start () {
p = pb.GetComponent<Rigidbody2D> ();
}
void Update () {
for (int i = 0; i < Input.touchCount; i++) {
Touch touch = Input.GetTouch (i);
if (touch.phase == TouchPhase.Ended && touch.tapCount == 1 ) {
Vector2 position = Camera.main.ScreenToWorldPoint (touch.position);
if(p.gravityScale==0.1f)
p.gravityScale=-0.1f;
}
else
p.gravityScale=0.1f;
}
}
}