void GetPhysicsChecks() { foreach (Check2D check in GetComponentsInChildren <Check2D>()) { if (check.type == Check2D.CheckType2D.ground) { groundCheck = check; } if (check.type == Check2D.CheckType2D.head) { headCheck = check; } } }
protected override void OnTriggerEnter2D(Collider2D otherCollider) { base.OnTriggerEnter2D(otherCollider); // Only consider falling if this isn't already doing so, and if colliding with a ground check Check2D groundCheck = otherCollider.gameObject.GetComponent <Check2D>(); bool considerFalling = !isFalling && groundCheck != null; if (!considerFalling) { return; } InvokeRepeating("Fall", fallDelay, Time.deltaTime); isFalling = true; }
void SetupChecks() { Check2D[] checks = GetComponentsInChildren <Check2D>(); foreach (Check2D check in checks) { switch (check.type) { case Check2D.CheckType2D.ground: groundCheck = check; break; case Check2D.CheckType2D.head: headCheck = check; break; } } // Need to respond to what the checks end up in contact with to decide the // state of this character groundCheck.contactEvents.TriggerEnter2D.AddListener(GroundCollisionEnter); groundCheck.contactEvents.TriggerExit2D.AddListener(GroundCollisionExit); headCheck.contactEvents.TriggerEnter2D.AddListener(HeadCollisionEnter); }