MIF_E31211986/Assets/Script/ButtonRight.cs

43 lines
1.1 KiB
C#

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;
public class ButtonRight : MonoBehaviour, IPointerDownHandler, IPointerUpHandler
{
public bool isHold;
public int speedRotasi;
GameObject objectRotasi;
// Update is called once per frame
void Update()
{
if (isHold)
{
RotasiObject();
}
}
public void OnPointerDown(PointerEventData data)
{
isHold = true;
}
public void OnPointerUp(PointerEventData data)
{
isHold = false;
}
void RotasiObject()
{
if (ButtonLeftRight.targetRotasi != null)
{
objectRotasi = ButtonLeftRight.targetRotasi; //mengambil objek dari script sebelah
objectRotasi.transform.localEulerAngles = new Vector3(0f, objectRotasi.transform.localEulerAngles.y + Time.deltaTime * speedRotasi, 0f); // (x, y, z)
Debug.Log("Rotating object: " + objectRotasi.name); // Menambahkan pesan debug untuk memeriksa apakah objek sedang dirotasi
}
}
}