Making an object drop when screen is touched
Alright so I'm having a bit of trouble with making an object floating on the screen fall when I touch the screen (on a mobile device)
I'm a beginner with code and I haven't been able to find a solution online as to how to make this possible.
Could anyone help me please?
Thanks.
you can disable gravity & enable it in script attached to the fallen object:
Rigidbody2D rgb;
void Start(){
rgb = GetComponent<Rigidbody2D>();
}
void Update(){
if (Input.touchCount > 0){
rgb.gravityScale = 1; // or what ever value. 0 will disable gravity
}
}
Answer by faizidp · Apr 20, 2016 at 09:27 AM
attach this script to an empty gameObject with 2d Collider attached... Scale it up to fit the whole screen.
public GameObject player; //attach player gameObject to this
void OnMouseDown(){
player.GetComponent().gravityScale=0;
}
Your answer
Follow this Question
Related Questions
Counteract gravity 2 Answers
local Physics 0 Answers
Object move around side window 0 Answers
Movement script preventing gravity 1 Answer
Using rb.velocity causes low gravity. 2 Answers