43 lines
1.1 KiB
C#
43 lines
1.1 KiB
C#
using UnityEngine;
|
|
using UnityEngine.EventSystems;
|
|
|
|
public class Screw : MonoBehaviour, IPointerDownHandler, IPointerUpHandler
|
|
{
|
|
private float requiredRotation = 360f * 2; // 需要旋转的总角度(例如3圈)
|
|
private float rotationAmount = 0f;
|
|
private bool isPressed = false;
|
|
|
|
private void Update()
|
|
{
|
|
if (isPressed)
|
|
{
|
|
float rotationSpeed = 360f; // 每秒旋转的角度
|
|
float deltaRotation = rotationSpeed * Time.deltaTime;
|
|
rotationAmount += deltaRotation;
|
|
transform.Rotate(Vector3.forward, deltaRotation);
|
|
|
|
if (rotationAmount >= requiredRotation)
|
|
{
|
|
Drop();
|
|
}
|
|
}
|
|
}
|
|
|
|
private void Drop()
|
|
{
|
|
gameObject.SetActive(false); // 螺丝掉落,可以替换成掉落动画
|
|
// 检查父物体的所有螺丝状态
|
|
transform.parent.parent.GetComponent<Module>().CheckAllScrews();
|
|
}
|
|
|
|
public void OnPointerDown(PointerEventData eventData)
|
|
{
|
|
isPressed = true;
|
|
}
|
|
|
|
public void OnPointerUp(PointerEventData eventData)
|
|
{
|
|
isPressed = false;
|
|
}
|
|
}
|