BITFALL/Assets/Artists/Scripts/Props/Prop_Shield.cs

61 lines
1.5 KiB
C#
Raw Normal View History

2023-10-30 01:25:53 +08:00
using System;
using System.Collections;
using System.Collections.Generic;
using BITKit;
using BITKit.Entities;
using UnityEngine;
using Random = UnityEngine.Random;
namespace BITFALL.Props
{
public class Prop_Shield : MonoBehaviour,IDamagable
{
[SerializeField] private SpringEulerAngle spring=new();
[SerializeField] private Optional<int> maxSpring;
2023-11-15 23:54:54 +08:00
[SerializeField] private Optional<LocationAdditive> locationAdditive;
2023-11-30 00:23:23 +08:00
[SerializeField] private Optional<Transform> optionalReset;
2023-10-30 01:25:53 +08:00
public IUnityEntity UnityEntity => null;
public Rigidbody Rigidbody => null;
private Vector3 initialEulerAngles;
private void Start()
{
initialEulerAngles = transform.localEulerAngles;
2023-10-31 18:07:15 +08:00
spring.value = initialEulerAngles;
2023-11-30 00:23:23 +08:00
if (optionalReset.Allow)
{
optionalReset.Value.rotation = Quaternion.LookRotation(
Vector3.ProjectOnPlane(
optionalReset.Value.forward,
Vector3.up)
);
}
2023-10-30 01:25:53 +08:00
}
private void FixedUpdate()
{
spring.Update(Time.fixedDeltaTime,initialEulerAngles);
transform.localEulerAngles = spring.value;
2023-11-15 23:54:54 +08:00
if (locationAdditive.Allow)
{
locationAdditive.Value.AddEuler(spring.value-initialEulerAngles);
}
2023-10-30 01:25:53 +08:00
}
public void GiveDamage(DamageMessage message)
{
var damage = message.Damage;
if (maxSpring.Allow)
{
damage = Mathf.Min(damage, maxSpring.Value);
}
spring.value =initialEulerAngles + new Vector3(
Random.Range(-damage, damage),
Random.Range(-damage, damage),
Random.Range(-damage, damage)
);
}
}
}