Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using System.Linq;
- using UnityEngine;
- public class CollisionDetection : MonoBehaviour
- {
- private void Update()
- {
- if (gameObject.layer == 2)
- {
- Ray ray = Camera.main.ScreenPointToRay(new Vector3(Input.mousePosition.x, Input.mousePosition.y, 1.0f));
- RaycastHit[] hitpoints = Physics.RaycastAll(ray).OrderBy(h => h.distance).ToArray(); //sort by distance
- foreach (RaycastHit hit in hitpoints)
- {
- if (hit.collider.gameObject != this.gameObject)
- {
- Vector3 newPos = hit.point;
- transform.position = newPos;
- break; //stop iterating
- }
- }
- }
- }
- private void OnTriggerEnter(Collider other)
- {
- if (other.gameObject.tag == "Untagged")
- {
- Debug.Log("<i>detected</i> " + other.gameObject.name);
- GameMaster.Instance.isCollided = true;
- }
- }
- private void OnTriggerExit(Collider other)
- {
- if (other.gameObject.tag == "Untagged")
- {
- Debug.Log("<i>OUT </i>" + other.gameObject.name);
- GameMaster.Instance.isCollided = false;
- }
- }
- private void OnCollisionEnter(Collision collision)
- {
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment