bool IsACrash(HitDetectionEventArgs args) { if (args.HitDirection == HitDirection.RightSide) { if (args.HittedObjectType == HittedObjectType.Platform) { return(true); } if (args.HittedObjectType == HittedObjectType.Enemy && _dashing == false) { return(true); } } if (args.HitDirection == HitDirection.Below) { if (args.HittedObjectType == HittedObjectType.Enemy && _dashing == false) { if (Request_CurrentPlayerState != null && Request_CurrentPlayerState.Invoke() == AnimState.Run) { return(true); } } } /*else*/ return(false); }
public void Handle_PlayerHittedObject(HitDetectionEventArgs args) { if (args.HitDirection == HitDirection.Above) { AllowAirDash(); } }
public void Handle_EnemyHit(HitDetectionEventArgs args) { if (args.HittedObjectType == HittedObjectType.Enemy) { var enemyController = args.HittedObject.GetComponent <EnemyController>(); enemyController.Handle_Hit(args.HitDirection); } }
public void Handle_PlayerHittedObject(HitDetectionEventArgs args) { switch (args.HitDirection) { case HitDirection.Above: ConsiderApplyingNewState(AnimState.HitGround); break; case HitDirection.Below: ConsiderApplyingNewState(AnimState.HitCeiling); break; default: /*Do nothing*/ break; } }
public void Handle_PlayerHittedObject(HitDetectionEventArgs args) { switch (args.HittedObjectType) { case HittedObjectType.Platform: PlayRandomSound(HitSounds); break; case HittedObjectType.Enemy: /*Presume it means that player smashed the enemy, otherwise PlayerCrashed event would have been invoked*/ PlayRandomSound(FruitSmashSounds); break; } }
void HitEnemyInFront() { var checkHit = AfterDashFrontEnemyDetector.GroundCheckHit(); if (checkHit.collider != null && DefineHittedObjectType(checkHit.collider.transform) == HittedObjectType.Enemy) { var eventArgs = new HitDetectionEventArgs() { HittedObject = checkHit.collider.gameObject, HittedObjectType = HittedObjectType.Enemy, HitPoint = checkHit.point, HitDirection = HitDirection.RightSide }; PlayerHittedObject?.Invoke(eventArgs); } }
// OnCollisionEnter2D is called when this collider2D/rigidbody2D has begun touching another rigidbody2D/collider2D (2D physics only) void OnCollisionEnter2D(Collision2D collision) { var hittedObject = collision.gameObject; var objectType = DefineHittedObjectType(collision.transform); var hitPoint = collision.GetContact(0).point; var hitDirection = DefineDirection(hitPoint, objectType); var eventArgs = new HitDetectionEventArgs() { HittedObject = hittedObject, HittedObjectType = objectType, HitPoint = hitPoint, HitDirection = hitDirection }; if (IsACrash(eventArgs)) { PlayerCrashed?.Invoke(); } else { PlayerHittedObject?.Invoke(eventArgs); } }