Initial commit

This commit is contained in:
lethanhsonvsp
2025-11-17 15:02:30 +07:00
commit 0a84b9d75e
15481 changed files with 2009655 additions and 0 deletions

View File

@@ -0,0 +1,56 @@
using UnityEngine;
public class ForkSensor : MonoBehaviour
{
public Transform forkLift; // Vị trí animation nâng/hạ
public Animator animator; // Bộ điều khiển animation
public FixedJoint joint; // Joint dùng để gắn pallet
public Rigidbody currentPallet; // Pallet đang tương tác
void Update()
{
if (Input.GetKeyDown(KeyCode.U)) // Up: nâng
{
animator.SetTrigger("Up");
AttachPallet();
}
if (Input.GetKeyDown(KeyCode.D)) // Down: hạ
{
animator.SetTrigger("Down");
DetachPallet();
}
}
void AttachPallet()
{
if (currentPallet == null) return;
// Tạo Joint nếu chưa có
if (joint == null)
{
joint = gameObject.AddComponent<FixedJoint>();
joint.connectedBody = currentPallet;
}
}
void DetachPallet()
{
if (joint != null)
{
Destroy(joint); // Tháo pallet
joint = null;
}
currentPallet = null;
}
// Tùy chọn: phát hiện pallet khi vào vùng sensor
private void OnTriggerEnter(Collider other)
{
if (other.CompareTag("Pallet"))
{
currentPallet = other.attachedRigidbody;
}
}
}