Initial commit
This commit is contained in:
38
Assets/Scripts/CarouselRotate.cs
Normal file
38
Assets/Scripts/CarouselRotate.cs
Normal file
@@ -0,0 +1,38 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class CarouselRotate : MonoBehaviour
|
||||
{
|
||||
[SerializeField] private Transform swing;
|
||||
[SerializeField] private float rotationSpeed = 60f;
|
||||
[SerializeField] private Vector3 rotationAxis = Vector3.up;
|
||||
|
||||
private bool _isActive;
|
||||
|
||||
private void Reset()
|
||||
{
|
||||
swing = transform.parent;
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
if (!_isActive || swing == null) return;
|
||||
|
||||
swing.Rotate(rotationAxis.normalized * rotationSpeed * Time.deltaTime, Space.Self);
|
||||
}
|
||||
|
||||
private void OnTriggerEnter(Collider other)
|
||||
{
|
||||
if (!other.CompareTag("Player")) return;
|
||||
|
||||
_isActive = true;
|
||||
}
|
||||
|
||||
private void OnTriggerExit(Collider other)
|
||||
{
|
||||
if (!other.CompareTag("Player")) return;
|
||||
|
||||
_isActive = false;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user