71 lines
1.8 KiB
C#
71 lines
1.8 KiB
C#
using UnityEngine;
|
|
|
|
[RequireComponent(typeof(Rigidbody))]
|
|
[RequireComponent(typeof(Collider))]
|
|
public class ProjectileBehaviour : MonoBehaviour
|
|
{
|
|
public enum ProjectileKind
|
|
{
|
|
Potato,
|
|
Knife
|
|
}
|
|
|
|
[Header("Projectile Data")]
|
|
public ProjectileKind kind;
|
|
public float baseDamage = 35f;
|
|
public float sigma = 2f;
|
|
public float directHitMultiplier = 1.15f;
|
|
public float breakImpulse = 1.8f;
|
|
public float lifeTime = 8f;
|
|
|
|
private Rigidbody rb;
|
|
private GlassRingController ring;
|
|
private float charge01;
|
|
private bool armed;
|
|
|
|
private void Awake()
|
|
{
|
|
rb = GetComponent<Rigidbody>();
|
|
}
|
|
|
|
public void Launch(GlassRingController ringController, Vector3 launchVelocity, float normalizedCharge)
|
|
{
|
|
ring = ringController;
|
|
charge01 = Mathf.Clamp01(normalizedCharge);
|
|
|
|
rb.linearVelocity = launchVelocity;
|
|
rb.angularVelocity = Vector3.zero;
|
|
|
|
armed = true;
|
|
|
|
Destroy(gameObject, lifeTime);
|
|
}
|
|
|
|
private void OnCollisionEnter(Collision collision)
|
|
{
|
|
if (!armed) return;
|
|
armed = false;
|
|
|
|
Vector3 hitPoint = collision.contactCount > 0
|
|
? collision.GetContact(0).point
|
|
: transform.position;
|
|
|
|
GlassPiece piece = collision.collider.GetComponentInParent<GlassPiece>();
|
|
if (piece != null && ring != null && !piece.IsBroken)
|
|
{
|
|
ring.ApplyProjectileImpact(piece.PieceIndex, this, charge01, hitPoint);
|
|
Destroy(gameObject);
|
|
return;
|
|
}
|
|
|
|
CenterButtonTarget button = collision.collider.GetComponentInParent<CenterButtonTarget>();
|
|
if (button != null)
|
|
{
|
|
button.NotifyHit(this);
|
|
Destroy(gameObject);
|
|
return;
|
|
}
|
|
|
|
Destroy(gameObject);
|
|
}
|
|
} |