Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using GoShared;
- namespace GoMap {
- public class GOCoordinatesRaycast : MonoBehaviour {
- public RoadManger roadManger;
- [HideInInspector]
- public Vector3 animalOldPos;
- [HideInInspector]
- public Quaternion animalOldRotation;
- [HideInInspector]
- public GameObject selectedAnimalObject;
- public RoadUiManger roadUiManger;
- public GameObject projectorPrefab;
- private GameObject currentProjector;
- public bool debugLog = false;
- public bool atomic = true;
- void SelectAnimal(GameObject gameObject)
- {
- GetComponent<GOOrbit>().SwitchCameraTarget(gameObject);
- CollectableAnimal collectableAnimal = gameObject.GetComponent<CollectableAnimal>();
- // Store the chosen animal data
- roadManger.chosenFromRoad = new AnimalDna(collectableAnimal.animalDna);
- roadUiManger._animalName = roadManger.chosenFromRoad.name;
- roadUiManger._level = roadManger.chosenFromRoad.level;
- // store it's old position, roation and object
- selectedAnimalObject = gameObject;
- animalOldPos = gameObject.transform.position;
- animalOldRotation = gameObject.transform.rotation;
- }
- void Update() {
- bool drag = false;
- if (Application.isMobilePlatform) {
- drag = Input.touchCount == 1 && Input.GetTouch (0).phase == TouchPhase.Began;
- } else
- drag = Input.GetMouseButton (0);
- #region Check choosen collectable animal
- if (Input.GetMouseButtonDown(0))
- {
- RaycastHit hit;
- Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
- if (Physics.Raycast(ray, out hit, Mathf.Infinity))
- {
- if (hit.transform.CompareTag("CollectableAnimal"))
- {
- GameObject _collectableAnimal = hit.transform.gameObject;
- SelectAnimal(_collectableAnimal);
- }
- }
- }
- #endregion
- if (drag) {
- RaycastHit hit;
- Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
- if (Physics.Raycast (ray, out hit,Mathf.Infinity,GOMap.GetActiveMasks())) {
- //From the raycast data it's easy to get the vector3 of the hit point
- Vector3 worldVector = hit.point;
- //And it's just as easy to get the gps coordinate of the hit point.
- Coordinates gpsCoordinates = Coordinates.convertVectorToCoordinates (hit.point);
- if (debugLog) {
- //There's a little debug string
- }
- if (currentProjector != null && atomic)
- GameObject.Destroy(currentProjector);
- //Add a simple projector to the tapped point
- currentProjector = GameObject.Instantiate(projectorPrefab);
- worldVector.y += 5.5f;
- currentProjector.transform.position = worldVector;
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement