···11+using System.Collections;
22+using System.Collections.Generic;
33+using UnityEngine;
44+55+public class PlayerSwing : MonoBehaviour {
66+77+ public GameObject Player;
88+ public float RepelSpeed = 5f;
99+1010+ /// <summary>
1111+ /// Awake is called when the script instance is being loaded.
1212+ /// </summary>
1313+ void Awake() {
1414+ Player = GameObject.FindWithTag("Player");
1515+ }
1616+1717+ /// <summary>
1818+ /// Sent when another object enters a trigger collider attached to this
1919+ /// object (2D physics only).
2020+ /// </summary>
2121+ /// <param name="other">The other Collider2D involved in this collision.</param>
2222+ void OnTriggerEnter2D(Collider2D other) => Trigger(other);
2323+2424+ /// <summary>
2525+ /// Sent each frame where another object is within a trigger collider
2626+ /// attached to this object (2D physics only).
2727+ /// </summary>
2828+ /// <param name="other">The other Collider2D involved in this collision.</param>
2929+ void OnTriggerStay2D(Collider2D other) => Trigger(other);
3030+3131+ void Trigger(Collider2D other ) {
3232+ if (!other.CompareTag("Enemy")) return;
3333+ var rigidbody = other.GetComponent<Rigidbody2D>();
3434+ if (rigidbody == null) return;
3535+ var diff = Player.transform.position - other.transform.position;
3636+ var dir = -diff.normalized;
3737+ rigidbody.velocity = RepelSpeed * dir;
3838+ }
3939+4040+}