55 lines
1.4 KiB
C#
55 lines
1.4 KiB
C#
using System.Collections;
|
|
using UnityEngine;
|
|
|
|
public class Rotate : MonoBehaviour
|
|
{
|
|
public float speed;
|
|
|
|
private string axis;
|
|
private bool isRotating;
|
|
|
|
void Update()
|
|
{
|
|
if (isRotating)
|
|
{
|
|
Debug.Log("Rotating on axis: " + axis);
|
|
|
|
if (axis.ToUpper() == "X")
|
|
{
|
|
transform.Rotate(Vector3.right * speed * Time.deltaTime);
|
|
}
|
|
else if (axis.ToUpper() == "Y")
|
|
{
|
|
transform.Rotate(Vector3.up * speed * Time.deltaTime);
|
|
}
|
|
else if (axis.ToUpper() == "Z")
|
|
{
|
|
transform.Rotate(Vector3.forward * speed * Time.deltaTime);
|
|
}
|
|
}
|
|
}
|
|
|
|
// Panggil RotateCube("Z") misalnya pada saat klik tombol atau input tertentu.
|
|
void Start()
|
|
{
|
|
RotateCube("Z");
|
|
// Invoke StopRotation setelah sejumlah detik, sesuai dengan durasi rotasi yang diinginkan.
|
|
Invoke("StopRotation", 2.0f); // Ganti nilai ini sesuai dengan durasi rotasi yang diinginkan.
|
|
}
|
|
|
|
// Fungsi untuk memulai rotasi pada sumbu tertentu.
|
|
public void RotateCube(string axis)
|
|
{
|
|
this.axis = axis;
|
|
isRotating = true;
|
|
Debug.Log("Rotasi dimulai pada sumbu: " + axis);
|
|
}
|
|
|
|
// Fungsi untuk menghentikan rotasi.
|
|
public void StopRotation()
|
|
{
|
|
isRotating = false;
|
|
Debug.Log("Rotasi dihentikan.");
|
|
}
|
|
}
|