dissertation / mainCode / UI / Menu.cs
Menu.cs
Raw
using System.Collections;
using System.Collections.Generic;
using TMPro;
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.UI;
using Slider = UnityEngine.UI.Slider;

public class Menu : MonoBehaviour
{
    
    private int BAD_VERTICAL_CROSSHAIR_PLACEMENT = 6;
    private int BAD_HORIZONTAL_CROSSHAIR_PLACEMENT = 13;
    private int BAD_MISSED_HORIZONTAL_SHOTS = 0;
    private int BAD_MISSED_VERTICAL_SHOTS = 0;
    private int BAD_DAMAGE_SOURCES = 1;
    private float BAD_ACCURACY = 1;
    private float BAD_HEADSHOT = 1;
    private float BAD_TIME_TO_KILL = 0.9f;
    private float BAD_TIME_TO_DAMAGE = 0.6f;
    
    // difficulty affecting values
    public float enemyNoticeRate = 0.6f; // speed at which enemy starts firing upon seeing you
    public float enemyDamage = 10; // damage of enemy bullets
    public float enemyFireRate = 0.6f; // minimum time between enemy shots
    public float enemyMaxFireRate = 1.5f;
    public float enemyAimModifier = 0.05f; // bullet spread of enemies
    public float playerHealRate = 0.05f; // amount player heals per successful shot
    public float enemyHealth = 100; // enemy maximum health
    public float enemySpawnRate = 5; // number of enemies spawning on the map at once
    public float enemySpeed = 1.5f;
    
    public bool hasSetUp = false;
    
    // Start is called before the first frame update
    void Start()
    {
        Cursor.lockState = CursorLockMode.None;
        Cursor.visible = true;
        SetInitialPrefs();
        
        if (!PlayerPrefs.HasKey("playerAccuracy"))
        {
            PlayerPrefs.SetInt("playerAccuracyEnabled", 1);
            PlayerPrefs.SetFloat("playerAccuracy", BAD_ACCURACY);
            PlayerPrefs.SetInt("playerHeadshotEnabled", 1);
            PlayerPrefs.SetFloat("playerHeadshot", BAD_HEADSHOT);
            PlayerPrefs.SetInt("playerTtdEnabled", 1);
            PlayerPrefs.SetFloat("playerTtd", BAD_TIME_TO_DAMAGE);
            PlayerPrefs.SetInt("playerTtkEnabled", 1);
            PlayerPrefs.SetFloat("playerTtk", BAD_TIME_TO_KILL);
            PlayerPrefs.SetInt("playerVerticalCrosshairEnabled", 1);
            PlayerPrefs.SetFloat("playerVerticalCrosshair", BAD_VERTICAL_CROSSHAIR_PLACEMENT);
            PlayerPrefs.SetInt("playerHorizontalCrosshairEnabled", 1);
            PlayerPrefs.SetFloat("playerHorizontalCrosshair", BAD_HORIZONTAL_CROSSHAIR_PLACEMENT);
            PlayerPrefs.SetInt("playerMissesEnabled", 1);
            PlayerPrefs.SetFloat("playerMisses", BAD_MISSED_VERTICAL_SHOTS);
            PlayerPrefs.SetInt("playerDamageSourcesEnabled", 1);
            PlayerPrefs.SetFloat("playerDamageSources", BAD_DAMAGE_SOURCES);
            PlayerPrefs.SetInt("playerHealthLossEnabled", 1);
            
            PlayerPrefs.SetInt("playerTrackingEnabled", 1);
            PlayerPrefs.SetFloat("mouseSensitivity", 20);
            PlayerPrefs.SetInt("graphicsEnabled", 1);
            PlayerPrefs.SetInt("textEnabled", 1);
            PlayerPrefs.SetInt("difficultyAdjustmentEnabled", 1);
            PlayerPrefs.SetFloat("audioVolume", 0.2f);
            PlayerPrefs.SetFloat("targetKills", 20);
            PlayerPrefs.SetInt("overallLevel", 20);
        }

        hasSetUp = true;
    }
    
    public void SetInitialPrefs()
    {
        if (!PlayerPrefs.HasKey("enemyNoticeRate"))
        {
            PlayerPrefs.SetFloat("enemyNoticeRate", enemyNoticeRate);
            PlayerPrefs.SetFloat("enemyDamage", enemyDamage);
            PlayerPrefs.SetFloat("enemyFireRate", enemyFireRate);
            PlayerPrefs.SetFloat("enemyMaxFireRate", enemyMaxFireRate);
            PlayerPrefs.SetFloat("enemyAimModifier", enemyAimModifier);
            PlayerPrefs.SetFloat("playerHealRate", playerHealRate);
            PlayerPrefs.SetFloat("enemyHealth", enemyHealth);
            PlayerPrefs.SetFloat("enemySpawnRate", enemySpawnRate);
            PlayerPrefs.SetFloat("enemySpeed", enemySpeed);
        }

        enemyNoticeRate = PlayerPrefs.GetFloat("enemyNoticeRate");
        enemyDamage = PlayerPrefs.GetFloat("enemyDamage");
        enemyFireRate = PlayerPrefs.GetFloat("enemyFireRate");
        enemyMaxFireRate = PlayerPrefs.GetFloat("enemyMaxFireRate");
        enemyAimModifier = PlayerPrefs.GetFloat("enemyAimModifier");
        playerHealRate = PlayerPrefs.GetFloat("playerHealRate");
        enemyHealth = PlayerPrefs.GetFloat("enemyHealth");
        enemySpawnRate = PlayerPrefs.GetFloat("enemySpawnRate");
        enemySpeed = PlayerPrefs.GetFloat("enemySpeed", enemySpeed);


    }
    
    public void LoadGame()
    {
        SceneManager.LoadScene("Game", LoadSceneMode.Single);
    }

    public void LoadOptions()
    {
        SceneManager.LoadScene("OptionsMenu", LoadSceneMode.Single);
    }
    
    public void QuitGame()
    {
        Application.Quit();
    }

    public void LoadCredits()
    {
        SceneManager.LoadScene("Credits", LoadSceneMode.Single);
    }
    
    
}