public void OnSuccessfulAttack(AttackType attackType, EnemyController enemy, Vector2 point) { //Debug.Log("hit " + enemy.gameObject.name + " with attack " + attackType.ToString()); if (attackType == AttackType.Jump || attackType == AttackType.Slam) { Vector2 inDirection = (point - (Vector2)transform.position).normalized; Vector2 inNormal = Vector2.up; Vector2 reflection = Vector2.Reflect(inDirection, inNormal); movementController.AddForce(reflection * 10.0f); vfxController.SpawnSwipeVFX(enemy.transform.position, Vector3.zero, Color.red); } else if (attackType == AttackType.Punch) { Vector2 inDirection = (point - (Vector2)transform.position).normalized; Vector2 inNormal = Vector2.up; Vector2 reflection = Vector2.Reflect(inDirection, inNormal); movementController.AddForce(reflection * 2.0f); vfxController.SpawnSwipeVFX(enemy.transform.position, Vector3.zero, Color.green); abilityController.hasPunch = true; } cameraController.Shake(0.02f, 0.01f, 0.25f); if (enemy is BasicEnemyController) { abilityController.hasPunch = true; } else if (enemy is ThumperEnemyController) { abilityController.hasSlam = true; } }
public override void GiveAttack() { Vector2 collideBoxOrigin = new Vector2(movementController.LastDirection * punchDistance + transform.position.x, transform.position.y); Collider2D collider = Physics2D.OverlapBox(collideBoxOrigin, new Vector2(0.5f, 0.2f), 0f, attackLayerMask); movementController.AddForce(Vector2.right * movementController.LastDirection * punchMoveForce); animator.SetTrigger("Attack"); vfxController.SpawnSwipeVFX(transform.position + new Vector3(movementController.LastDirection / 2, 0, 0), Vector3.zero, Color.white, movementController.LastDirection == 1 ? true : false); soundController.PlayAttack(); if (collider == null) { return; } PlayerController p = collider.gameObject.GetComponent <PlayerController>(); if (p) { p.ReceiveAttack(this); Debug.DrawLine(transform.position, p.transform.position, Color.red); } }