SHADE_Y3/Assets/Scripts/Gameplay/SC_CeilingFan.cs

80 lines
2.8 KiB
C#

using SHADE;
using SHADE_Scripting.Audio;
using System;
public class CeilingFan : Script
{
private Transform tran;
private Collider collider;
private float rotate = 0.0f;
public float rotateSpeed = 10.0f;
private float rotateCollider1 = 0.0f;
private float rotateCollider2 = 0.0f;
private float rotateCollider3 = 0.0f;
private float rotateCollider4 = 0.0f;
private float rotateCollider5 = 0.0f;
private float defaultCollider1 = 0.0f;
private float defaultCollider2 = 0.0f;
private float defaultCollider3 = 0.0f;
private float defaultCollider4 = 0.0f;
private float defaultCollider5 = 0.0f;
protected override void awake()
{
tran = GetComponent<Transform>();
if (!tran)
Debug.Log("FAN TRAN MISSING");
collider = GetComponent<Collider>();
if (!collider)
Debug.Log("FAN COLLIDER MISSING");
else
{
rotateCollider1 = collider.GetCollisionShape(0).RotationOffset.y;
defaultCollider1 = collider.GetCollisionShape(0).RotationOffset.y;
rotateCollider2 = collider.GetCollisionShape(1).RotationOffset.y;
defaultCollider2 = collider.GetCollisionShape(1).RotationOffset.y;
rotateCollider3 = collider.GetCollisionShape(2).RotationOffset.y;
defaultCollider3 = collider.GetCollisionShape(2).RotationOffset.y;
rotateCollider4 = collider.GetCollisionShape(3).RotationOffset.y;
defaultCollider4 = collider.GetCollisionShape(3).RotationOffset.y;
rotateCollider5 = collider.GetCollisionShape(4).RotationOffset.y;
defaultCollider5 = collider.GetCollisionShape(4).RotationOffset.y;
}
}
protected override void fixedUpdate()
{
rotate += rotateSpeed * (float)Time.FixedDeltaTime;
rotateCollider1 += rotateSpeed * (float)Time.FixedDeltaTime;
rotateCollider2 += rotateSpeed * (float)Time.FixedDeltaTime;
rotateCollider3 += rotateSpeed * (float)Time.FixedDeltaTime;
rotateCollider4 += rotateSpeed * (float)Time.FixedDeltaTime;
rotateCollider5 += rotateSpeed * (float)Time.FixedDeltaTime;
if (rotate >= MathF.PI * 2)
{
rotate = 0;
rotateCollider1 = defaultCollider1;
rotateCollider2 = defaultCollider2;
rotateCollider3 = defaultCollider3;
rotateCollider4 = defaultCollider4;
rotateCollider5 = defaultCollider5;
}
tran.LocalEulerAngles = new Vector3(0.0f, rotate, 0.0f);
collider.GetCollisionShape(0).RotationOffset = new Vector3(0.0f, rotateCollider1, 0.0f);
collider.GetCollisionShape(1).RotationOffset = new Vector3(0.0f, rotateCollider2, 0.0f);
collider.GetCollisionShape(2).RotationOffset = new Vector3(0.0f, rotateCollider3, 0.0f);
collider.GetCollisionShape(3).RotationOffset = new Vector3(0.0f, rotateCollider4, 0.0f);
collider.GetCollisionShape(4).RotationOffset = new Vector3(0.0f, rotateCollider5, 0.0f);
}
}