oof ouch owie
This commit is contained in:
parent
e29208a2e5
commit
3364b5df68
5 changed files with 122 additions and 14 deletions
23
Assets/Scripts/BeamCollider.cs
Normal file
23
Assets/Scripts/BeamCollider.cs
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
using System;
|
||||
using UnityEngine;
|
||||
|
||||
public class BeamCollider : MonoBehaviour
|
||||
{
|
||||
public Laser thisLaser;
|
||||
|
||||
private void OnTriggerEnter2D(Collider2D other)
|
||||
{
|
||||
if (!other.CompareTag(thisLaser.thisPlayer.tag) && other.TryGetComponent(out Entity isEntity))
|
||||
{
|
||||
thisLaser.enemyList.Add(isEntity);
|
||||
}
|
||||
}
|
||||
|
||||
private void OnTriggerExit2D(Collider2D other)
|
||||
{
|
||||
if (!other.CompareTag(thisLaser.thisPlayer.tag) && other.TryGetComponent(out Entity isEntity) && thisLaser.enemyList.Contains(isEntity))
|
||||
{
|
||||
thisLaser.enemyList.Remove(isEntity);
|
||||
}
|
||||
}
|
||||
}
|
||||
2
Assets/Scripts/BeamCollider.cs.meta
Normal file
2
Assets/Scripts/BeamCollider.cs.meta
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
fileFormatVersion: 2
|
||||
guid: fa1b7388657a56c7a91ace02c52cd5ee
|
||||
|
|
@ -1,4 +1,5 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Core.Extensions;
|
||||
using UnityEngine;
|
||||
|
||||
|
|
@ -10,11 +11,15 @@ public class Laser : PlayerAbility
|
|||
public float duration;
|
||||
private float currentDuration;
|
||||
[Header("Beam")]
|
||||
[SerializeField] private GameObject beamObject;
|
||||
private GameObject beamObjectInstance;
|
||||
[SerializeField] private BeamCollider beamObject;
|
||||
private BeamCollider beamObjectInstance;
|
||||
public float turnSpeed;
|
||||
public float offset;
|
||||
|
||||
[Header("Weapon Properties")]
|
||||
[HideInInspector] public List<Entity> enemyList = new();
|
||||
public float damageDebounceTime;
|
||||
private float currentDebounce;
|
||||
public float damage;
|
||||
private void Start()
|
||||
{
|
||||
CreateBeam();
|
||||
|
|
@ -24,7 +29,8 @@ public class Laser : PlayerAbility
|
|||
{
|
||||
canCooldown = false;
|
||||
currentDuration = duration;
|
||||
beamObjectInstance.SetActive(true);
|
||||
currentDebounce = damageDebounceTime;
|
||||
beamObjectInstance.gameObject.SetActive(true);
|
||||
transform.Lookat2D(thisPlayer.mouseWorldPos);
|
||||
}
|
||||
|
||||
|
|
@ -36,10 +42,27 @@ public class Laser : PlayerAbility
|
|||
float angle = Mathf.Atan2(direction.y, direction.x) * Mathf.Rad2Deg;
|
||||
transform.rotation = Quaternion.RotateTowards(beamObjectInstance.transform.rotation, Quaternion.Euler(0,0,angle), turnSpeed * Time.deltaTime);
|
||||
currentDuration -= Time.deltaTime;
|
||||
if (currentDebounce > 0)
|
||||
{
|
||||
currentDebounce -= Time.deltaTime;
|
||||
if (currentDebounce <= 0)
|
||||
{
|
||||
foreach (Entity enemy in enemyList.ToArray())
|
||||
{
|
||||
if (!enemy)
|
||||
{
|
||||
enemyList.Remove(enemy);
|
||||
continue;
|
||||
}
|
||||
enemy.TakeDamage(damage);
|
||||
}
|
||||
currentDebounce = damageDebounceTime;
|
||||
}
|
||||
}
|
||||
if (currentDuration <= 0)
|
||||
{
|
||||
canCooldown = true;
|
||||
beamObjectInstance.SetActive(false);
|
||||
beamObjectInstance.gameObject.SetActive(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -50,11 +73,7 @@ public class Laser : PlayerAbility
|
|||
beamObjectInstance.transform.SetParent(transform);
|
||||
beamObjectInstance.transform.localScale = new Vector3(length, width, 1);
|
||||
beamObjectInstance.transform.Translate(Vector3.right * (beamObjectInstance.transform.localScale.x * 0.5f) + new Vector3(offset, 0, 0));
|
||||
beamObjectInstance.SetActive(false);
|
||||
}
|
||||
|
||||
private void DetectEnemies()
|
||||
{
|
||||
|
||||
beamObjectInstance.thisLaser = this;
|
||||
beamObjectInstance.gameObject.SetActive(false);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue