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