Advertisement
Guest User

Untitled

a guest
Aug 21st, 2019
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.09 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using GoShared;
  5.  
  6. namespace GoMap {
  7.  
  8. public class GOCoordinatesRaycast : MonoBehaviour {
  9.  
  10. public RoadManger roadManger;
  11.  
  12. [HideInInspector]
  13. public Vector3 animalOldPos;
  14. [HideInInspector]
  15. public Quaternion animalOldRotation;
  16. [HideInInspector]
  17. public GameObject selectedAnimalObject;
  18.  
  19.  
  20. public RoadUiManger roadUiManger;
  21. public GameObject projectorPrefab;
  22. private GameObject currentProjector;
  23.  
  24. public bool debugLog = false;
  25. public bool atomic = true;
  26.  
  27. void SelectAnimal(GameObject gameObject)
  28. {
  29. GetComponent<GOOrbit>().SwitchCameraTarget(gameObject);
  30. CollectableAnimal collectableAnimal = gameObject.GetComponent<CollectableAnimal>();
  31.  
  32. // Store the chosen animal data
  33. roadManger.chosenFromRoad = new AnimalDna(collectableAnimal.animalDna);
  34.  
  35. roadUiManger._animalName = roadManger.chosenFromRoad.name;
  36. roadUiManger._level = roadManger.chosenFromRoad.level;
  37.  
  38. // store it's old position, roation and object
  39. selectedAnimalObject = gameObject;
  40. animalOldPos = gameObject.transform.position;
  41. animalOldRotation = gameObject.transform.rotation;
  42. }
  43. void Update() {
  44.  
  45. bool drag = false;
  46. if (Application.isMobilePlatform) {
  47. drag = Input.touchCount == 1 && Input.GetTouch (0).phase == TouchPhase.Began;
  48. } else
  49. drag = Input.GetMouseButton (0);
  50.  
  51. #region Check choosen collectable animal
  52. if (Input.GetMouseButtonDown(0))
  53. {
  54. RaycastHit hit;
  55. Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
  56. if (Physics.Raycast(ray, out hit, Mathf.Infinity))
  57. {
  58.  
  59. if (hit.transform.CompareTag("CollectableAnimal"))
  60. {
  61. GameObject _collectableAnimal = hit.transform.gameObject;
  62. SelectAnimal(_collectableAnimal);
  63. }
  64. }
  65. }
  66. #endregion
  67.  
  68. if (drag) {
  69. RaycastHit hit;
  70. Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
  71. if (Physics.Raycast (ray, out hit,Mathf.Infinity,GOMap.GetActiveMasks())) {
  72.  
  73.  
  74. //From the raycast data it's easy to get the vector3 of the hit point
  75. Vector3 worldVector = hit.point;
  76. //And it's just as easy to get the gps coordinate of the hit point.
  77. Coordinates gpsCoordinates = Coordinates.convertVectorToCoordinates (hit.point);
  78.  
  79. if (debugLog) {
  80. //There's a little debug string
  81. }
  82.  
  83. if (currentProjector != null && atomic)
  84. GameObject.Destroy(currentProjector);
  85.  
  86. //Add a simple projector to the tapped point
  87. currentProjector = GameObject.Instantiate(projectorPrefab);
  88. worldVector.y += 5.5f;
  89. currentProjector.transform.position = worldVector;
  90. }
  91. }
  92. }
  93.  
  94.  
  95.  
  96.  
  97. }
  98. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement