Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEngine.UI;
- using UnityEngine.SceneManagement;
- public class PickUp : MonoBehaviour
- {
- Camera camera;
- public int totalCubeCount;
- int currentCubeCount = 0;
- //public Text cubeCountText;
- bool cubeVisible;
- bool nextLevelDoorVisible;
- // Use this for initialization
- void Awake()
- {
- camera = transform.GetChild(0).GetComponent<Camera>();
- }
- // Update is called once per frame
- void Update()
- {
- if (camera != null)
- {
- RaycastHit hit;
- Ray ray = camera.ScreenPointToRay(Input.mousePosition);
- if (Physics.Raycast(ray, out hit))
- {
- Transform objectHit = hit.transform;
- if (objectHit.tag == "Cube")
- {
- cubeVisible = true;
- if (Input.GetKeyDown(KeyCode.E))
- {
- objectHit.gameObject.SetActive(false);
- currentCubeCount += 1;
- cubeVisible = false;
- //cubeCountText.text = "Cubes Found: " + currentCubeCount + "/" + totalCubeCount;
- }
- }
- else
- {
- cubeVisible = false;
- }
- }
- if (Physics.Raycast(ray, out hit))
- {
- if (hit.transform.tag == "NextLevelDoor")
- {
- nextLevelDoorVisible = true;
- if (Input.GetKeyDown(KeyCode.E))
- {
- SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex + 1);
- }
- }
- else
- {
- nextLevelDoorVisible = false;
- }
- }
- }
- else
- {
- Debug.Log("No Camera Found");
- }
- }
- void OnGUI()
- {
- if (cubeVisible)
- {
- GUI.Label(new Rect(Screen.width / 2 - 75, Screen.height - 100, 150, 30), "Press 'E' to collect cube");
- }
- if (nextLevelDoorVisible)
- {
- GUI.Label(new Rect(Screen.width / 2 - 75, Screen.height - 100, 150, 30), "Press 'E' to advance to the next level");
- }
- GUIStyle cubeCountStyle = new GUIStyle(GUI.skin.label);
- cubeCountStyle.fontSize = 30;
- GUIStyle cubeCountStyleAllFound = new GUIStyle(GUI.skin.label);
- cubeCountStyleAllFound.fontSize = 30;
- cubeCountStyleAllFound.normal.textColor = Color.green;
- if (currentCubeCount != totalCubeCount)
- {
- GUI.Label(new Rect(10, 10, 300, 60), "Cubes Found: " + currentCubeCount + "/" + totalCubeCount, cubeCountStyle);
- }
- else
- {
- GUI.Label(new Rect(10, 10, 300, 60), "Cubes Found: " + currentCubeCount + "/" + totalCubeCount, cubeCountStyleAllFound);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement