studycase2
This commit is contained in:
81
Assets/BTM_Assets/BTM_Items_Gems/Scripts/SimpleGemsAnim.cs
Normal file
81
Assets/BTM_Assets/BTM_Items_Gems/Scripts/SimpleGemsAnim.cs
Normal file
@@ -0,0 +1,81 @@
|
||||
using UnityEngine;
|
||||
using System.Collections;
|
||||
|
||||
namespace Benjathemaker
|
||||
{
|
||||
public class SimpleGemsAnim : MonoBehaviour
|
||||
{
|
||||
public bool isRotating = false;
|
||||
public bool rotateX = false;
|
||||
public bool rotateY = false;
|
||||
public bool rotateZ = false;
|
||||
public float rotationSpeed = 90f; // Degrees per second
|
||||
|
||||
public bool isFloating = false;
|
||||
public bool useEasingForFloating = false; // Separate toggle for floating ease
|
||||
public float floatHeight = 1f; // Max height displacement
|
||||
public float floatSpeed = 1f;
|
||||
private Vector3 initialPosition;
|
||||
private float floatTimer;
|
||||
|
||||
private Vector3 initialScale;
|
||||
public Vector3 startScale;
|
||||
public Vector3 endScale;
|
||||
|
||||
public bool isScaling = false;
|
||||
public bool useEasingForScaling = false; // Separate toggle for scaling ease
|
||||
public float scaleLerpSpeed = 1f; // Speed of scaling transition
|
||||
private float scaleTimer;
|
||||
|
||||
void Start()
|
||||
{
|
||||
initialScale = transform.localScale;
|
||||
initialPosition = transform.position;
|
||||
|
||||
// Adjust start and end scale based on initial scale
|
||||
startScale = initialScale;
|
||||
endScale = initialScale * (endScale.magnitude / startScale.magnitude);
|
||||
}
|
||||
|
||||
void Update()
|
||||
{
|
||||
if (isRotating)
|
||||
{
|
||||
Vector3 rotationVector = new Vector3(
|
||||
rotateX ? 1 : 0,
|
||||
rotateY ? 1 : 0,
|
||||
rotateZ ? 1 : 0
|
||||
);
|
||||
transform.Rotate(rotationVector * rotationSpeed * Time.deltaTime);
|
||||
}
|
||||
|
||||
if (isFloating)
|
||||
{
|
||||
floatTimer += Time.deltaTime * floatSpeed;
|
||||
float t = Mathf.PingPong(floatTimer, 1f);
|
||||
if (useEasingForFloating) t = EaseInOutQuad(t);
|
||||
|
||||
transform.position = initialPosition + new Vector3(0, t * floatHeight, 0);
|
||||
}
|
||||
|
||||
if (isScaling)
|
||||
{
|
||||
scaleTimer += Time.deltaTime * scaleLerpSpeed;
|
||||
float t = Mathf.PingPong(scaleTimer, 1f); // Oscillates between 0 and 1
|
||||
|
||||
if (useEasingForScaling)
|
||||
{
|
||||
t = EaseInOutQuad(t);
|
||||
}
|
||||
|
||||
transform.localScale = Vector3.Lerp(startScale, endScale, t);
|
||||
}
|
||||
}
|
||||
|
||||
float EaseInOutQuad(float t)
|
||||
{
|
||||
return t < 0.5f ? 2 * t * t : 1 - Mathf.Pow(-2 * t + 2, 2) / 2;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 845c415f3181b4840ab566c40e714752
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user