You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
62 lines
1.3 KiB
C#
62 lines
1.3 KiB
C#
using UnityEngine;
|
|
|
|
public class Draggable : MonoBehaviour
|
|
{
|
|
private Camera cam;
|
|
private Rigidbody rb;
|
|
private float fixedZ;
|
|
private bool isOverMouth = false;
|
|
|
|
void Start()
|
|
{
|
|
cam = Camera.main;
|
|
rb = GetComponent<Rigidbody>();
|
|
fixedZ = transform.position.z;
|
|
}
|
|
|
|
void OnMouseDown()
|
|
{
|
|
rb.useGravity = false;
|
|
rb.velocity = Vector3.zero;
|
|
}
|
|
|
|
void OnMouseDrag()
|
|
{
|
|
Vector3 mousePos = Input.mousePosition;
|
|
mousePos.z = fixedZ - cam.transform.position.z;
|
|
|
|
Vector3 worldPos = cam.ScreenToWorldPoint(mousePos);
|
|
transform.position = new Vector3(worldPos.x, worldPos.y, fixedZ);
|
|
}
|
|
|
|
void OnMouseUp()
|
|
{
|
|
rb.useGravity = true;
|
|
|
|
if (isOverMouth)
|
|
{
|
|
bool accepted = FeedingManager.Instance.TryFeed();
|
|
if (accepted)
|
|
{
|
|
Destroy(gameObject); // Only destroy if feeding accepted
|
|
}
|
|
}
|
|
}
|
|
|
|
void OnTriggerEnter(Collider other)
|
|
{
|
|
if (other.CompareTag("Mouth"))
|
|
{
|
|
isOverMouth = true;
|
|
}
|
|
}
|
|
|
|
void OnTriggerExit(Collider other)
|
|
{
|
|
if (other.CompareTag("Mouth"))
|
|
{
|
|
isOverMouth = false;
|
|
}
|
|
}
|
|
}
|