Sword Halo & Arrow to the nearest enemy

This commit is contained in:
2023-10-17 10:55:31 +02:00
parent eb51da13ed
commit ec1084bd10
23 changed files with 1097 additions and 3 deletions
+33
View File
@@ -0,0 +1,33 @@
using UnityEngine;
[RequireComponent (typeof(BoxCollider2D))]
public class Sword : MonoBehaviour
{
public int Damages = 25;
private void Update()
{
RotateSword();
}
private void RotateSword()
{
// LookAt 2D
Vector3 target = transform.parent.position;
// get the angle
Vector3 norTar = (target - transform.position).normalized;
float angle = Mathf.Atan2(norTar.y, norTar.x) * Mathf.Rad2Deg;
// rotate to angle
Quaternion rotation = new();
rotation.eulerAngles = new Vector3(0, 0, angle - 180);
transform.rotation = rotation;
}
private void OnTriggerEnter2D(Collider2D collision)
{
if (collision.CompareTag("Ennemy") && collision.gameObject != null)
{
collision.GetComponent<Ennemy>().Life -= Damages;
}
}
}