Advertisement
Guest User

Untitled

a guest
Nov 14th, 2018
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.07 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.UI;
  5. using UnityEngine.SceneManagement;
  6.  
  7. public class PickUp : MonoBehaviour
  8. {
  9. Camera camera;
  10. public int totalCubeCount;
  11. int currentCubeCount = 0;
  12. //public Text cubeCountText;
  13. bool cubeVisible;
  14. bool nextLevelDoorVisible;
  15.  
  16. // Use this for initialization
  17. void Awake()
  18. {
  19. camera = transform.GetChild(0).GetComponent<Camera>();
  20. }
  21.  
  22. // Update is called once per frame
  23. void Update()
  24. {
  25. if (camera != null)
  26. {
  27. RaycastHit hit;
  28. Ray ray = camera.ScreenPointToRay(Input.mousePosition);
  29.  
  30. if (Physics.Raycast(ray, out hit))
  31. {
  32. Transform objectHit = hit.transform;
  33.  
  34. if (objectHit.tag == "Cube")
  35. {
  36. cubeVisible = true;
  37.  
  38. if (Input.GetKeyDown(KeyCode.E))
  39. {
  40. objectHit.gameObject.SetActive(false);
  41. currentCubeCount += 1;
  42. cubeVisible = false;
  43. //cubeCountText.text = "Cubes Found: " + currentCubeCount + "/" + totalCubeCount;
  44. }
  45. }
  46. else
  47. {
  48. cubeVisible = false;
  49. }
  50. }
  51. if (Physics.Raycast(ray, out hit))
  52. {
  53. if (hit.transform.tag == "NextLevelDoor" && currentCubeCount == totalCubeCount)
  54. {
  55. nextLevelDoorVisible = true;
  56.  
  57. if (Input.GetKeyDown(KeyCode.E))
  58. {
  59. SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex + 1);
  60. }
  61. }
  62. else
  63. {
  64. nextLevelDoorVisible = false;
  65. }
  66. }
  67. }
  68. else
  69. {
  70. Debug.Log("No Camera Found");
  71. }
  72. }
  73.  
  74. void OnGUI()
  75. {
  76.  
  77. if (cubeVisible)
  78. {
  79. GUI.Label(new Rect(Screen.width / 2 - 75, Screen.height - 100, 150, 30), "Press 'E' to collect cube");
  80. }
  81.  
  82. if (nextLevelDoorVisible)
  83. {
  84. GUI.Label(new Rect(Screen.width / 2 - 75, Screen.height - 100, 150, 30), "Press 'E' to advance to the next level");
  85. }
  86.  
  87. GUIStyle cubeCountStyle = new GUIStyle(GUI.skin.label);
  88. cubeCountStyle.fontSize = 30;
  89. GUIStyle cubeCountStyleAllFound = new GUIStyle(GUI.skin.label);
  90. cubeCountStyleAllFound.fontSize = 30;
  91. cubeCountStyleAllFound.normal.textColor = Color.green;
  92.  
  93.  
  94. if (currentCubeCount != totalCubeCount)
  95. {
  96. GUI.Label(new Rect(10, 10, 300, 60), "Cubes Found: " + currentCubeCount + "/" + totalCubeCount, cubeCountStyle);
  97. }
  98. else
  99. {
  100. GUI.Label(new Rect(10, 10, 300, 60), "Cubes Found: " + currentCubeCount + "/" + totalCubeCount, cubeCountStyleAllFound);
  101. }
  102. }
  103.  
  104. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement