Quiero que esto funcione como un laser que sigue el mouse del jugador using…
- User
Quiero que esto funcione como un laser que sigue el mouse del jugador
using Game.Systems; using MoreMountains.Feedbacks; using UnityEngine; using UnityEngine.Serialization;
namespace Game.Spells { public class DarkBeam: Spell { [SerializeField] private float totalDuration; [SerializeField] private float damagePerInterval; [SerializeField] private LayerMask enemyLayer; // Reference to the layer that enemies are on. [SerializeField] private MMF_Player fireSound; private float damageInterval = 0.5f; // The time interval for applying damage. private float damageTimer; private float durationTimer;
public override void Init() { base.Init(); damageTimer = 0f; durationTimer = 0f; ParticleSystem[] childParticleSystems = GetComponentsInChildren<ParticleSystem>(); foreach (ParticleSystem ps in childParticleSystems) { ps.Play(); } fireSound.PlayFeedbacks(); InvokeRepeating(nameof(ApplyDamage), 0f, damageInterval); // Start applying damage immediately. } // This method applies damage to all enemies in the circular area. private void ApplyDamage() { Collider[] hitColliders = Physics.OverlapCapsule(transform.position - Vector3.up * 10f, transform.position + Vector3.up * 10f, AreaSize, enemyLayer); foreach (Collider hitCollider in hitColliders) { UnitHealth unitHealth = hitCollider.GetComponent<UnitHealth>(); if (unitHealth) { unitHealth.TakeDamage(damagePerInterval * damageInterval); } } } private void Update() { // Timer to control the duration of the spell. durationTimer += Time.deltaTime; if (durationTimer >= totalDuration) { CancelInvoke(nameof(ApplyDamage)); // Stop applying damage. ParticleSystem[] childParticleSystems = GetComponentsInChildren<ParticleSystem>(); foreach (ParticleSystem ps in childParticleSystems) { ps.Stop(); } Destroy(gameObject, GetComponent<ParticleSystem>().main.duration); // Clean up the spell object. } } private void OnDestroy() { CancelInvoke(nameof(ApplyDamage)); // Ensure the repeating damage is stopped. } }}
Usa algo como para determinar la colision con el terreno, quiero que el daño sea continuo no por intervalos como está ahorita
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); RaycastHit hit;
if (Physics.Raycast(ray, out hit, Mathf.Infinity, layerMaskTerrain)) {}
- Assistant