51 lines
1.2 KiB
C#
51 lines
1.2 KiB
C#
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;
|
|
[SerializeField] private Optional<LocationAdditive> locationAdditive;
|
|
public IUnityEntity UnityEntity => null;
|
|
public Rigidbody Rigidbody => null;
|
|
private Vector3 initialEulerAngles;
|
|
|
|
private void Start()
|
|
{
|
|
initialEulerAngles = transform.localEulerAngles;
|
|
spring.value = initialEulerAngles;
|
|
}
|
|
private void FixedUpdate()
|
|
{
|
|
spring.Update(Time.fixedDeltaTime,initialEulerAngles);
|
|
transform.localEulerAngles = spring.value;
|
|
if (locationAdditive.Allow)
|
|
{
|
|
locationAdditive.Value.AddEuler(spring.value-initialEulerAngles);
|
|
}
|
|
}
|
|
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)
|
|
);
|
|
}
|
|
|
|
}
|
|
|
|
}
|