Guest User

Untitled

a guest
Jan 22nd, 2018
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.95 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.UI;
  5.  
  6. public class Map : MonoBehaviour
  7. {
  8. public Camera mapCamera;
  9. public Text objectWasHit;
  10. public GameObject mouseOvered;
  11. public float distanceToHit = 1000;
  12.  
  13. private Camera[] cameras;
  14. private List<GameObject> objectsToHit = new List<GameObject>();
  15.  
  16. // Use this for initialization
  17. void Start()
  18. {
  19. cameras = Camera.allCameras;
  20.  
  21. GameObject levels = GameObject.Find("_Level");
  22. foreach (Transform child in levels.transform)
  23. {
  24. child.gameObject.AddComponent<UnityEngine.MeshRenderer>();
  25. objectsToHit.Add(child.gameObject);
  26. }
  27. }
  28.  
  29. // Update is called once per frame
  30. void Update()
  31. {
  32. if (Input.GetKeyDown(KeyCode.M))
  33. {
  34. if (mapCamera.enabled == false)
  35. {
  36. foreach (Camera cam in cameras)
  37. {
  38. cam.enabled = false;
  39. }
  40. mapCamera.enabled = true;
  41. }
  42. else
  43. {
  44. foreach (Camera cam in cameras)
  45. {
  46. cam.enabled = true;
  47. }
  48. mapCamera.enabled = false;
  49. }
  50. }
  51.  
  52. bool rcHit = false;
  53. Vector3 mouse = Input.mousePosition;
  54. Ray castPoint = mapCamera.ScreenPointToRay(mouse);
  55. RaycastHit hit;
  56. Debug.DrawRay(castPoint.origin, castPoint.direction * distanceToHit, Color.magenta);
  57. if (Physics.Raycast(castPoint, out hit, distanceToHit))
  58. {
  59. rcHit = true;
  60. if (mouseOvered != hit.collider.gameObject)
  61. {
  62. mouseOvered = hit.collider.gameObject;
  63. }
  64. objectWasHit.text = mouseOvered.name;
  65. }
  66.  
  67. if (!rcHit && mouseOvered != null)
  68. {
  69. mouseOvered = null;
  70. }
  71. }
  72. }
  73.  
  74. objectWasHit.text = mouseOvered.name;
Add Comment
Please, Sign In to add comment