54 lines
1.3 KiB
C#
54 lines
1.3 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using DG.Tweening;
|
|
|
|
public class Screwdriver : Tool
|
|
{
|
|
private int rotationCount = 0;
|
|
private int requiredRotations = 5;
|
|
private bool isFixing = false; // 是否在维修状态
|
|
|
|
public override void UseTool(Vector3 targetPosition)
|
|
{
|
|
// 检查是否在维修状态
|
|
if (isFixing && IsOverScrewSlot(targetPosition))
|
|
{
|
|
StartRemoveScrew();
|
|
}
|
|
}
|
|
|
|
public void StartFixMode()
|
|
{
|
|
isFixing = true; // 设置为维修模式
|
|
}
|
|
|
|
private bool IsOverScrewSlot(Vector3 position)
|
|
{
|
|
// 假设使用碰撞检测或其他方法确认是否靠近螺丝槽位
|
|
// 可以在此实现实际的检测逻辑
|
|
return true; // 简单返回true用于测试
|
|
}
|
|
|
|
private void StartRemoveScrew()
|
|
{
|
|
// 螺丝旋转动画
|
|
transform.DORotate(new Vector3(0, 0, -90), 0.5f, RotateMode.LocalAxisAdd).OnComplete(() =>
|
|
{
|
|
rotationCount++;
|
|
if (rotationCount >= requiredRotations)
|
|
{
|
|
RemoveScrew();
|
|
}
|
|
});
|
|
}
|
|
|
|
private void RemoveScrew()
|
|
{
|
|
Debug.Log("Screw removed");
|
|
rotationCount = 0;
|
|
// 可以加入螺丝掉落的逻辑,比如销毁对象或改变其状态
|
|
}
|
|
}
|
|
|