I’m trying to detect if a ship’s left and right landing gear are on the landing pad, indicating a success or landing failure (if one landing gear collides but not the other).
Each landing gear is its own game object and they both have their own box colliders -all within a prefab
Problem is both conditions (landing success and landing failure) end up evaluating to true regardless if both landing gear are on the pad or only one.
The following code is attached to the landing platform:
usingUnityEngine;
usingSystem.Collections;
usingSystem.Collections.Generic;
public classCollision : MonoBehaviour {
boollandingGearLeftOnPad = false;
boollandingGearRightOnPad = false;
void Start () {}
void Update () {
}
voidOnCollisionEnter2D (Collision2Dcoll) {
if (coll.gameObject.tag == "LandingGearLeft"){
landingGearLeftOnPad = true;
//Debug.Log("LeftLandingGearonPad");
}
if (coll.gameObject.tag == "LandingGearRight"){
landingGearRightOnPad = true;
}
if (landingGearLeftOnPad && landingGearRightOnPad){
Debug.Log("Landed Successfully");
}
if (landingGearLeftOnPad && !landingGearRightOnPad){
Debug.Log("You missed the landing pad");
}
if (!landingGearLeftOnPad && landingGearRightOnPad){
Debug.Log("You missed the landing pad");
}
}
voidOnCollisionExit2D (Collision2Dcoll){
landingGearLeftOnPad = false;
landingGearRightOnPad = false;
}
}