59 lines
1.4 KiB
C#
59 lines
1.4 KiB
C#
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using Lightbug.Utilities;
|
|
using UnityEngine;
|
|
#if UNITY_EDITOR
|
|
using UnityEditor;
|
|
#endif
|
|
|
|
namespace BITFALL.Scenes
|
|
{
|
|
[ExecuteAlways]
|
|
public class AnimatorBasedPlatform : MonoBehaviour
|
|
{
|
|
[SerializeField] private float mass;
|
|
[SerializeField] private Animator animator;
|
|
[SerializeField] private RigidbodyComponent rigidbodyComponent;
|
|
private Vector3 currentPosition;
|
|
private Quaternion currentRotation;
|
|
private void Start()
|
|
{
|
|
#if UNITY_EDITOR
|
|
if(EditorApplication.isPlaying is false)
|
|
return;
|
|
#endif
|
|
rigidbodyComponent = gameObject.AddComponent<RigidbodyComponent3D>();
|
|
var transform1 = transform;
|
|
currentPosition = transform1.position;
|
|
currentRotation=transform1.rotation;
|
|
rigidbodyComponent.UseGravity = false;
|
|
rigidbodyComponent.Mass = mass;
|
|
rigidbodyComponent.IsKinematic = true;
|
|
}
|
|
private void FixedUpdate()
|
|
{
|
|
#if UNITY_EDITOR
|
|
if(EditorApplication.isPlaying is false)
|
|
return;
|
|
#endif
|
|
rigidbodyComponent.MoveAndRotate(currentPosition,currentRotation);
|
|
}
|
|
private void OnAnimatorMove()
|
|
{
|
|
animator.ApplyBuiltinRootMotion();
|
|
#if UNITY_EDITOR
|
|
// if (EditorApplication.isPlaying is false)
|
|
// {
|
|
// transform.position = animator.rootPosition;
|
|
// transform.rotation = animator.rootRotation;
|
|
// }
|
|
#endif
|
|
|
|
currentPosition = animator.rootPosition;
|
|
currentRotation = animator.rootRotation;
|
|
}
|
|
}
|
|
|
|
}
|