Question by
Flashmangagames · Feb 16, 2016 at 09:30 AM ·
c#physicsif-statements
Is it possible to put collision detection in an if statement?
Is there any way to put collision detection into an if statement?
Here is an example of what i mean:
void JumpButtonPressed () {
if (Collided with platform){
GetComponent<Rigidbody>().AddForce (Vector3.up * 210, ForceMode.Acceleration);
}
}
Note that I am using Unity 5 and that I am coding in C#.
Comment
You could always have a bool isGrounded. And then in the two function OnCollisionEnter and OnCollisionExit set it to false/true and check for that.
Often half the job is to come up with alternative solutions to a problem :P