Commit 1
This commit is contained in:
69
Assets/Scripts/VFX/SukunaAbilityController.cs
Normal file
69
Assets/Scripts/VFX/SukunaAbilityController.cs
Normal file
@@ -0,0 +1,69 @@
|
||||
using UnityEngine;
|
||||
using OnlyScove.Scripts;
|
||||
|
||||
public class SukunaAbilityController : MonoBehaviour
|
||||
{
|
||||
[Header("Dependencies")]
|
||||
[SerializeField] private InputReader inputReader;
|
||||
|
||||
[Header("VFX Projectiles")]
|
||||
public GameObject blackProjectilePrefab;
|
||||
public GameObject redProjectilePrefab;
|
||||
|
||||
[Header("Settings")]
|
||||
public float attackRate = 0.15f;
|
||||
public float forwardOffset = 1.5f;
|
||||
public float verticalOffset = 1.0f;
|
||||
|
||||
[Header("Random Rotation Ranges")]
|
||||
public Vector2 rangeX = new Vector2(-360f, 360f);
|
||||
public Vector2 rangeY = new Vector2(-10f, 10f);
|
||||
public Vector2 rangeZ = new Vector2(50f, 120f);
|
||||
|
||||
private float lastAttackTime = 0f;
|
||||
|
||||
private void Update()
|
||||
{
|
||||
if (inputReader != null && inputReader.IsAttackHeld)
|
||||
{
|
||||
if (Time.time - lastAttackTime >= attackRate)
|
||||
{
|
||||
PerformDismantle();
|
||||
lastAttackTime = Time.time;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void PerformDismantle()
|
||||
{
|
||||
GameObject selectedPrefab = GetRandomSlashVariant();
|
||||
if (selectedPrefab == null) return;
|
||||
|
||||
// Vị trí spawn trước mặt Player
|
||||
Vector3 spawnPos = transform.position + transform.forward * forwardOffset + Vector3.up * verticalOffset;
|
||||
|
||||
// Tạo góc xoay ngẫu nhiên theo yêu cầu của bạn
|
||||
float randX = Random.Range(rangeX.x, rangeX.y);
|
||||
float randY = Random.Range(rangeY.x, rangeY.y);
|
||||
float randZ = Random.Range(rangeZ.x, rangeZ.y);
|
||||
|
||||
// Kết hợp với hướng của Player
|
||||
Quaternion spawnRot = transform.rotation * Quaternion.Euler(randX, randY, randZ);
|
||||
|
||||
// Tạo đạn
|
||||
GameObject projectile = Instantiate(selectedPrefab, spawnPos, spawnRot);
|
||||
|
||||
// Bắt đạn bay về phía trước (hướng nhìn của Player)
|
||||
if (projectile.TryGetComponent<SukunaProjectile>(out var projScript))
|
||||
{
|
||||
projScript.SetDirection(transform.forward);
|
||||
}
|
||||
}
|
||||
|
||||
private GameObject GetRandomSlashVariant()
|
||||
{
|
||||
float chance = Random.Range(0f, 100f);
|
||||
if (chance <= 20f) return redProjectilePrefab != null ? redProjectilePrefab : blackProjectilePrefab;
|
||||
return blackProjectilePrefab;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user