ProjetAMJV_CR/Assets/Scripts/UnitScripts/Attacks/Projectiles/ProjectileHandler.cs
2025-01-20 21:05:28 +01:00

37 lines
874 B
C#

using Unity.VisualScripting;
using UnityEngine;
/// <summary>
/// Should be attached to the Arrow, not the skeleton
/// </summary>
[RequireComponent(typeof(Rigidbody))]
public class ProjectileHandler : MonoBehaviour
{
[SerializeField] protected float _lifeSpan = 8.0f;
protected Rigidbody RigidBody;
protected bool FromTeamA;
void Awake()
{
RigidBody = GetComponent<Rigidbody>();
}
void Start()
{
// Destroy after _lifeSpan, in all case
Destroy(this.gameObject, _lifeSpan);
}
void Update()
{
// Align with speed
if (RigidBody.linearVelocity.magnitude >= 1f) transform.forward = RigidBody.linearVelocity.normalized;
}
public void LaunchProjectile(Vector3 baseSpeed, bool fromTeamA)
{
RigidBody.linearVelocity = baseSpeed;
FromTeamA = fromTeamA;
}
}