Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using UnityEngine.UI;
- using UnityEngine.SceneManagement;
- public class Main : MonoBehaviour
- {
- [HideInInspector] public int cameraNumber = 1;
- [HideInInspector] public bool hasLookedLeft = false;
- [HideInInspector] public bool hasLookedRight = false;
- [HideInInspector] public bool hasCrouched = false;
- [HideInInspector] public bool isJumpscare = false;
- [HideInInspector] public bool isCameraActive = false;
- public static int night = 1;
- public static int nightHour = 12;
- private int currentTexture;
- private int heKnowsHowToPlay = 0;
- private float amountOfTime = 360f;
- private float timeBetwenTextures;
- private string roomName;
- private bool isPhoneCallMuted = false;
- [Header("Components:")]
- [HideInInspector] public PanAI panAI;
- [HideInInspector] public MikeyAI mikeyAI;
- [SerializeField] private Text nightHourText;
- [SerializeField] private Text roomNameText;
- [Space]
- [SerializeField] private Button[] buttons; // Buttons: Cam01AButton -> Cam07BButton, CamButtonOn, CamButtonOff, MuteCallButton
- [SerializeField] private Texture[] staticEffectTextures;
- [SerializeField] private AudioClip[] mainAudioClip; // AudioClips: camsOffSFX, camButtonSFX, PhoneHangUp, camsOnSFX
- private Transform mainCameraTransform;
- private AudioSource mainAudioSource;
- private RawImage staticEffect;
- private Animator mainAnimator;
- [Header ("GameObjects:")]
- public GameObject cameraButtonOn;
- public GameObject cameraButtonOff;
- [Space]
- [SerializeField] private GameObject cameraSystem;
- [SerializeField] private GameObject officeCamera;
- [SerializeField] private GameObject staticEffectObject;
- [SerializeField] private GameObject callButton;
- [SerializeField] private GameObject framerate;
- [SerializeField] private GameObject keyboardControls;
- [SerializeField] private GameObject mouseControls;
- [Space]
- [SerializeField] private GameObject[] cameraSystemObjects; // Objects: CameraStatic, Cam01AButton -> Cam07BButton, MAP, RoomName
- [SerializeField] private GameObject[] callObjects; // Objetcs: Call, MuteCallButton
- [SerializeField] private GameObject[] cameras; // Objects: Main Camera, Cam01A -> Cam07B
- [SerializeField] private GameObject[] lookTriggers;
- private GameObject mikeyObject;
- private GameObject panObject;
- void Awake()
- {
- // We make sure the game is unpaused in case the player pauses the game and exits
- PauseMenu.isPaused = false;
- // We enable the framerate display depending on the option
- if (Framerate.showFPS)
- {
- framerate.SetActive(true);
- }
- else
- {
- framerate.SetActive(false);
- }
- // We enable the look triggers and help depending on the option
- if (MainCamera.isMouseControls)
- {
- foreach (GameObject triggers in lookTriggers)
- {
- triggers.SetActive(true);
- }
- if (PlayerPrefs.GetInt("heKnows") == 0)
- {
- mouseControls.SetActive(true);
- }
- }
- else
- {
- foreach (GameObject triggers in lookTriggers)
- {
- triggers.SetActive(false);
- }
- if (PlayerPrefs.GetInt("heKnows") == 0)
- {
- keyboardControls.SetActive(true);
- }
- }
- // We delete the camera related keys so each time the player starts a night it doesent remember the last camera he was looking at
- PlayerPrefs.DeleteKey("cam");
- PlayerPrefs.DeleteKey("camName");
- SetAIlevel();
- }
- void Start()
- {
- // We search for the objects that hold the animatronics AI script in the scene
- mikeyObject = GameObject.Find("Mikey");
- panObject = GameObject.Find("Pan");
- // We get a specified component from the game objects and assign it to a variable
- mainCameraTransform = officeCamera.GetComponent<Transform>();
- staticEffect = staticEffectObject.GetComponent<RawImage>();
- mainAudioSource = cameraSystem.GetComponent<AudioSource>();
- mainAnimator = officeCamera.GetComponent<Animator>();
- mikeyAI = mikeyObject.GetComponent<MikeyAI>();
- panAI = panObject.GetComponent<PanAI>();
- // We activate the mute call button 7s after the scene starts and remove it in 30s
- Invoke(nameof(ActivateCallButton), 7f);
- Invoke(nameof(RemoveCallButton), 30f);
- }
- void Update()
- {
- // We decrease the variable value by 1 each second
- amountOfTime -= Time.deltaTime;
- NightTime();
- StaticEffect();
- // Used to skip the nights, DEBUG ONLY
- /*if (Input.GetKey(KeyCode.LeftShift))
- {
- if (Input.GetKeyDown(KeyCode.Q))
- {
- SceneManager.LoadScene("6AM");
- }
- }*/
- // If the player pauses the game it does the same with the phone call and makes the camera buttons to not be interacteble unless you unpause
- if (PauseMenu.isPaused && !isPhoneCallMuted)
- {
- GameObject.Find("Call").GetComponent<AudioSource>().Pause();
- foreach (Button button in buttons)
- {
- button.interactable = false;
- }
- }
- else if (!PauseMenu.isPaused && !isPhoneCallMuted)
- {
- GameObject.Find("Call").GetComponent<AudioSource>().UnPause();
- foreach (Button button in buttons)
- {
- button.interactable = true;
- }
- }
- // We disable the help menu if the player presses 'X'
- if (Input.GetKeyDown(KeyCode.X))
- {
- keyboardControls.SetActive(false);
- mouseControls.SetActive(false);
- heKnowsHowToPlay = 1;
- PlayerPrefs.SetInt("heKnows", heKnowsHowToPlay);
- PlayerPrefs.Save();
- }
- }
- void EnableCameraUsing_cameraNumber( Int cameraNumber )
- {
- foreach (GameObject cam in cameras)
- {
- cam.SetActive(false);
- }
- cameras[ cameraNumber ].SetActive(true);
- }
- public void ActivateCamSys()
- {
- // We check to make sure the player wont be able to use the camera system if the player lookes right, left, it crouches and if is in the middle in the jumpscare
- if (!mainAnimator.GetBool("isLeft") && !mainAnimator.GetBool("isRight") && !mainAnimator.GetBool("isHideing") && !isJumpscare)
- {
- // We enable the camera system
- foreach (GameObject cam in cameraSystemObjects)
- {
- cam.SetActive(true);
- }
- // We check if the player uses the camera for the first time during the night, if not it sets the lable to Halway 1 else it sets the lable to the last camera he was
- if (PlayerPrefs.GetString("camName") == "")
- {
- roomNameText.text = "Hallway 1";
- }
- else
- {
- roomNameText.text = PlayerPrefs.GetString("camName");
- }
- // We reset the poition and rotation of the player camera to default
- mainCameraTransform.position = new Vector3(15f, 1f, 11f);
- mainCameraTransform.rotation = Quaternion.Euler(0f, 0f, 0f);
- // We say that the camera is active
- isCameraActive = true;
- // We make the ambient light brighter
- RenderSettings.ambientLight = new Color(0.11f, 0.11f, 0.11f);
- // We switch the camera button to the one that turns it off
- cameraButtonOn.SetActive(false);
- cameraButtonOff.SetActive(true);
- // We disable the look triggers if the setting is enabled
- if (MainCamera.isMouseControls)
- {
- foreach (GameObject triggers in lookTriggers)
- {
- triggers.SetActive(false);
- }
- }
- // Makes the static effect more visible then less visible for cool effect
- staticEffect.CrossFadeAlpha(100, 0.1f, false);
- Invoke(nameof(StaticEffectToNormalOppacity), 0.1f);
- // We play the SFX for the camera turning on
- mainAudioSource.clip = mainAudioClip[3];
- mainAudioSource.Play();
- // We disable the mainCamera
- officeCamera.SetActive(false);
- // Gets the cameraNumber we remembered
- PlayerPrefs.GetInt("cam");
- EnableCameraUsing_cameraNumber( cameraNumber );
- }
- }
- public void DeactivateCamSys()
- {
- // We disable the camera system
- foreach (GameObject cam in cameraSystemObjects)
- {
- cam.SetActive(false);
- }
- // We say that the camera is not active anymore
- isCameraActive = false;
- // We set the ambient light back to normal
- RenderSettings.ambientLight = Color.black;
- // We enable the look triggers if the setting is enabled
- if (MainCamera.isMouseControls)
- {
- foreach (GameObject triggers in lookTriggers)
- {
- triggers.SetActive(true);
- }
- }
- //We switch the camera button to the one that turns it on
- cameraButtonOn.SetActive(true);
- cameraButtonOff.SetActive(false);
- // We play the SFX for the camera turning off
- mainAudioSource.clip = mainAudioClip[0];
- mainAudioSource.Play();
- // We Disable all the cameras in the scene
- foreach (GameObject cam in cameras)
- {
- cam.SetActive(false);
- }
- // We enable the office camera
- officeCamera.SetActive(true);
- }
- public void Camera01A()
- {
- // Plays a sound when clicking the button
- mainAudioSource.clip = mainAudioClip[1];
- mainAudioSource.Play();
- // Sets the camera number then the camera label
- cameraNumber = 1;
- roomName = "Hallway 1";
- roomNameText.text = roomName;
- // Cool static effect
- staticEffect.CrossFadeAlpha(100, 0.1f, false);
- Invoke(nameof(StaticEffectToNormalOppacity), 0.1f);
- // Remembers the camera number and the camera name
- PlayerPrefs.SetString("camName", roomName);
- PlayerPrefs.SetInt("cam", cameraNumber);
- PlayerPrefs.Save();
- // Disables all the cameras in the scene
- foreach (GameObject cam in cameras)
- {
- cam.SetActive(false);
- }
- // Enables the proper camera
- cameras[1].SetActive(true);
- }
- public void Camera01B()
- {
- mainAudioSource.clip = mainAudioClip[1];
- mainAudioSource.Play();
- cameraNumber = 2;
- roomName = "Hallway 2";
- roomNameText.text = roomName;
- staticEffect.CrossFadeAlpha(100, 0.1f, false);
- Invoke(nameof(StaticEffectToNormalOppacity), 0.1f);
- PlayerPrefs.SetString("camName", roomName);
- PlayerPrefs.SetInt("cam", cameraNumber);
- PlayerPrefs.Save();
- foreach (GameObject cam in cameras)
- {
- cam.SetActive(false);
- }
- cameras[2].SetActive(true);
- }
- public void Camera01C()
- {
- mainAudioSource.clip = mainAudioClip[1];
- mainAudioSource.Play();
- roomName = "Hallway 3";
- roomNameText.text = roomName;
- cameraNumber = 3;
- staticEffect.CrossFadeAlpha(100, 0.1f, false);
- Invoke(nameof(StaticEffectToNormalOppacity), 0.1f);
- PlayerPrefs.SetString("camName", roomName);
- PlayerPrefs.SetInt("cam", cameraNumber);
- PlayerPrefs.Save();
- foreach (GameObject cam in cameras)
- {
- cam.SetActive(false);
- }
- cameras[3].SetActive(true);
- }
- public void Camera02()
- {
- mainAudioSource.clip = mainAudioClip[1];
- mainAudioSource.Play();
- roomName = "Bedroom";
- roomNameText.text = roomName;
- cameraNumber = 4;
- staticEffect.CrossFadeAlpha(100, 0.1f, false);
- Invoke(nameof(StaticEffectToNormalOppacity), 0.1f);
- PlayerPrefs.SetString("camName", roomName);
- PlayerPrefs.SetInt("cam", cameraNumber);
- PlayerPrefs.Save();
- foreach (GameObject cam in cameras)
- {
- cam.SetActive(false);
- }
- cameras[4].SetActive(true);
- }
- public void Camera03()
- {
- mainAudioSource.clip = mainAudioClip[1];
- mainAudioSource.Play();
- roomName = "Storage Room";
- roomNameText.text = roomName;
- cameraNumber = 5;
- staticEffect.CrossFadeAlpha(100, 0.1f, false);
- Invoke(nameof(StaticEffectToNormalOppacity), 0.1f);
- PlayerPrefs.SetString("camName", roomName);
- PlayerPrefs.SetInt("cam", cameraNumber);
- PlayerPrefs.Save();
- foreach (GameObject cam in cameras)
- {
- cam.SetActive(false);
- }
- cameras[5].SetActive(true);
- }
- public void Camera04()
- {
- mainAudioSource.clip = mainAudioClip[1];
- mainAudioSource.Play();
- roomName = "Kitchen";
- roomNameText.text = roomName;
- cameraNumber = 6;
- staticEffect.CrossFadeAlpha(100, 0.1f, false);
- Invoke(nameof(StaticEffectToNormalOppacity), 0.1f);
- PlayerPrefs.SetString("camName", roomName);
- PlayerPrefs.SetInt("cam", cameraNumber);
- PlayerPrefs.Save();
- foreach (GameObject cam in cameras)
- {
- cam.SetActive(false);
- }
- cameras[6].SetActive(true);
- }
- public void Camera05()
- {
- mainAudioSource.clip = mainAudioClip[1];
- mainAudioSource.Play();
- roomName = "Dining Room";
- roomNameText.text = roomName;
- cameraNumber = 7;
- staticEffect.CrossFadeAlpha(100, 0.1f, false);
- Invoke(nameof(StaticEffectToNormalOppacity), 0.1f);
- PlayerPrefs.SetString("camName", roomName);
- PlayerPrefs.SetInt("cam", cameraNumber);
- PlayerPrefs.Save();
- foreach (GameObject cam in cameras)
- {
- cam.SetActive(false);
- }
- cameras[7].SetActive(true);
- }
- public void Camera06()
- {
- mainAudioSource.clip = mainAudioClip[1];
- mainAudioSource.Play();
- roomName = "Restroom";
- roomNameText.text = roomName;
- cameraNumber = 8;
- staticEffect.CrossFadeAlpha(100, 0.1f, false);
- Invoke(nameof(StaticEffectToNormalOppacity), 0.1f);
- PlayerPrefs.SetString("camName", roomName);
- PlayerPrefs.SetInt("cam", cameraNumber);
- PlayerPrefs.Save();
- foreach (GameObject cam in cameras)
- {
- cam.SetActive(false);
- }
- cameras[8].SetActive(true);
- }
- public void Camera07A()
- {
- mainAudioSource.clip = mainAudioClip[1];
- mainAudioSource.Play();
- roomName = "Play Room";
- roomNameText.text = roomName;
- cameraNumber = 9;
- staticEffect.CrossFadeAlpha(100, 0.1f, false);
- Invoke(nameof(StaticEffectToNormalOppacity), 0.1f);
- PlayerPrefs.SetString("camName", roomName);
- PlayerPrefs.SetInt("cam", cameraNumber);
- PlayerPrefs.Save();
- foreach (GameObject cam in cameras)
- {
- cam.SetActive(false);
- }
- cameras[9].SetActive(true);
- }
- public void Camera07B()
- {
- mainAudioSource.clip = mainAudioClip[1];
- mainAudioSource.Play();
- roomName = "Stage";
- roomNameText.text = roomName;
- cameraNumber = 10;
- staticEffect.CrossFadeAlpha(100, 0.1f, false);
- Invoke(nameof(StaticEffectToNormalOppacity), 0.1f);
- PlayerPrefs.SetString("camName", roomName);
- PlayerPrefs.SetInt("cam", cameraNumber);
- PlayerPrefs.Save();
- foreach (GameObject cam in cameras)
- {
- cam.SetActive(false);
- }
- cameras[10].SetActive(true);
- }
- public void MuteCall()
- {
- // Plays a beep sound when we mute the call
- mainAudioSource.clip = mainAudioClip[2];
- mainAudioSource.Play();
- // We say that the call is muted
- isPhoneCallMuted = true;
- // We disable the objects from the array to mute the call
- foreach (GameObject call in callObjects)
- {
- call.SetActive(false);
- }
- }
- private void NightTime()
- {
- // We check the time
- if (Mathf.Floor(amountOfTime) == 300f)
- {
- // We set the values
- amountOfTime = 300f;
- nightHour = 1;
- // We call the functions from the AILevel script
- AIlevel.PanMovingTime();
- AIlevel.MikeyMovingTime();
- // We check if animatronics are at the door
- if (panAI.currentCamera != 4 && mikeyAI.currentCamera != 5)
- {
- // We reset the time betwen movement
- panAI.timeBetwenMovement = Random.Range(PanAI.minTimeBetwenMovement, PanAI.maxTimeBetwenMovement);
- mikeyAI.timeBetwenMovement = Random.Range(MikeyAI.minTimeBetwenMovement, MikeyAI.maxTimeBetwenMovement);
- }
- // We display the time on screen
- nightHourText.text = $"{nightHour} AM";
- }
- else if (Mathf.Floor(amountOfTime) == 240f)
- {
- amountOfTime = 240f;
- nightHour = 2;
- AIlevel.PanMovingTime();
- AIlevel.MikeyMovingTime();
- if (panAI.currentCamera != 4 && mikeyAI.currentCamera != 5)
- {
- panAI.timeBetwenMovement = Random.Range(PanAI.minTimeBetwenMovement, PanAI.maxTimeBetwenMovement);
- mikeyAI.timeBetwenMovement = Random.Range(MikeyAI.minTimeBetwenMovement, MikeyAI.maxTimeBetwenMovement);
- }
- nightHourText.text = $"{nightHour} AM";
- }
- else if (Mathf.Floor(amountOfTime) == 180f)
- {
- amountOfTime = 180f;
- nightHour = 3;
- AIlevel.PanMovingTime();
- AIlevel.MikeyMovingTime();
- if (panAI.currentCamera != 4 && mikeyAI.currentCamera != 5)
- {
- panAI.timeBetwenMovement = Random.Range(PanAI.minTimeBetwenMovement, PanAI.maxTimeBetwenMovement);
- mikeyAI.timeBetwenMovement = Random.Range(MikeyAI.minTimeBetwenMovement, MikeyAI.maxTimeBetwenMovement);
- }
- nightHourText.text = $"{nightHour} AM";
- }
- else if (Mathf.Floor(amountOfTime) == 120f)
- {
- amountOfTime = 120f;
- nightHour = 4;
- AIlevel.PanMovingTime();
- AIlevel.MikeyMovingTime();
- if (panAI.currentCamera != 4 && mikeyAI.currentCamera != 5)
- {
- panAI.timeBetwenMovement = Random.Range(PanAI.minTimeBetwenMovement, PanAI.maxTimeBetwenMovement);
- mikeyAI.timeBetwenMovement = Random.Range(MikeyAI.minTimeBetwenMovement, MikeyAI.maxTimeBetwenMovement);
- }
- nightHourText.text = $"{nightHour} AM";
- }
- else if (Mathf.Floor(amountOfTime) == 60f)
- {
- amountOfTime = 60f;
- nightHour = 5;
- AIlevel.PanMovingTime();
- AIlevel.MikeyMovingTime();
- if (panAI.currentCamera != 4 && mikeyAI.currentCamera != 5)
- {
- panAI.timeBetwenMovement = Random.Range(PanAI.minTimeBetwenMovement, PanAI.maxTimeBetwenMovement);
- mikeyAI.timeBetwenMovement = Random.Range(MikeyAI.minTimeBetwenMovement, MikeyAI.maxTimeBetwenMovement);
- }
- nightHourText.text = $"{nightHour} AM";
- }
- else if (Mathf.Floor(amountOfTime) == 0f)
- {
- amountOfTime = 0f;
- nightHour = 6;
- nightHourText.text = $"{nightHour} AM";
- SceneManager.LoadSceneAsync("6AM");
- }
- }
- private void SetAIlevel()
- {
- // We set the AI agression level to a value depending on the night
- if (night == 1)
- {
- PanAI.PanAIlevel = 1;
- MikeyAI.MikeyAIlevel = 1;
- }
- else if (night == 2)
- {
- PanAI.PanAIlevel = 5;
- MikeyAI.MikeyAIlevel = 5;
- }
- else if (night == 3)
- {
- PanAI.PanAIlevel = 5;
- MikeyAI.MikeyAIlevel = 5;
- }
- else if (night == 4)
- {
- PanAI.PanAIlevel = 5;
- MikeyAI.MikeyAIlevel = 5;
- }
- else if (night == 5)
- {
- PanAI.PanAIlevel = 5;
- MikeyAI.MikeyAIlevel = 5;
- }
- }
- private void StaticEffectToNormalOppacity()
- {
- // Sets the static effect to his normal opacity
- staticEffect.CrossFadeAlpha(1, 0.1f, false);
- }
- private void ActivateCallButton()
- {
- // Activates the mute call button
- callButton.SetActive(true);
- }
- private void RemoveCallButton()
- {
- // Disables the mute call button
- callButton.SetActive(false);
- }
- private void StaticEffect()
- {
- // It switches betwen each texture from the array in a short amount of time
- timeBetwenTextures -= Time.deltaTime;
- if (timeBetwenTextures < 0)
- {
- timeBetwenTextures = 0;
- }
- if (timeBetwenTextures == 0)
- {
- currentTexture++;
- currentTexture %= staticEffectTextures.Length;
- staticEffect.texture = staticEffectTextures[currentTexture];
- timeBetwenTextures = 0.08f;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement