Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class TokenBehaviour : MonoBehaviour
- {
- private Vector3 mOffset;
- private Vector3 startingPosition;
- private Vector3 slotPosition;
- private float mZCoord;
- private bool triggered = false;
- private Rigidbody rBody;
- void Start()
- {
- rBody = GetComponent<Rigidbody>();
- }
- private void OnMouseDown()
- {
- startingPosition = transform.position;
- transform.position = transform.position + new Vector3(0, 2, 0);
- mZCoord = Camera.main.WorldToScreenPoint(gameObject.transform.position).z;
- mOffset = gameObject.transform.position - GetMouseWorldPos();
- }
- private void OnMouseUp()
- {
- if (triggered)
- {
- //Debug.Log("Entered volume");
- Debug.Log(slotPosition.ToString("F3"));
- //transform.position = slotPosition;
- rBody.MovePosition(slotPosition);
- rBody.velocity = Vector3.zero;
- }
- else
- {
- transform.position = startingPosition;
- //rBody.MovePosition(startingPosition);
- rBody.velocity = Vector3.zero;
- }
- //rBody.detectCollisions = true;
- //rBody.isKinematic = false;
- }
- private Vector3 GetMouseWorldPos()
- {
- Vector3 mousePoint = Input.mousePosition;
- mousePoint.z = mZCoord;
- return Camera.main.ScreenToWorldPoint(mousePoint);
- }
- private void OnMouseDrag()
- {
- transform.position = GetMouseWorldPos() + mOffset;
- transform.position = new Vector3(transform.position.x, 4, transform.position.z);
- }
- void OnTriggerEnter(Collider other)
- {
- if (other.gameObject.CompareTag("Trigger Volume"))
- {
- triggered = true;
- slotPosition = other.gameObject.transform.position;
- //slotPosition.z = -2.69F;
- }
- //rBody.detectCollisions = false;
- //rBody.isKinematic = true;
- }
- void OnTriggerExit(Collider other)
- {
- if (other.gameObject.CompareTag("Trigger Volume"))
- {
- triggered = false;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement