Scripts - drdynamitekoe/CIS6035---Dissertation-Project GitHub Wiki
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class cameraMovement : MonoBehaviour
{
[SerializeField] private float _turnSpeed = 3f;
private void Update()
{
float horizontal = Input.GetAxis("Mouse X");
transform.Rotate(horizontal * _turnSpeed * Vector3.up, Space.World);
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class cameraSwitcher : MonoBehaviour {
public GameObject camera1; //The first person camera
public GameObject camera2; //The third person camera
public GameObject camera3; //The rear view camera
public GameObject camera4; //The rear view camera
public GameObject camera5; //The rear view camera
public GameObject camera6; //The rear view camera
// Update is called once per frame
void Update()
{
if (Input.GetKey(KeyCode.Alpha1)) //If the button is pressed
{
camera1.SetActive(true); //The camera is changed to first person mode
camera2.SetActive(false); //The third person camera is disabled
camera3.SetActive(false); //The rear view camera is disabled
camera4.SetActive(false); //The rear view camera is disabled
camera5.SetActive(false); //The rear view camera is disabled
camera6.SetActive(false); //The rear view camera is disabled
}
if (Input.GetKey(KeyCode.Alpha2)) //If the button is pressed
{
camera1.SetActive(false); //The camera is changed to first person mode
camera2.SetActive(true); //The third person camera is disabled
camera3.SetActive(false); //The rear view camera is disabled
camera4.SetActive(false); //The rear view camera is disabled
camera5.SetActive(false); //The rear view camera is disabled
camera6.SetActive(false); //The rear view camera is disabled
}
if (Input.GetKey(KeyCode.Alpha3)) //If the button is pressed
{
camera1.SetActive(false); //The camera is changed to first person mode
camera2.SetActive(false); //The third person camera is disabled
camera3.SetActive(true); //The rear view camera is disabled
camera4.SetActive(false); //The rear view camera is disabled
camera5.SetActive(false); //The rear view camera is disabled
camera6.SetActive(false); //The rear view camera is disabled
}
if (Input.GetKey(KeyCode.Alpha4)) //If the button is pressed
{
camera1.SetActive(false); //The camera is changed to first person mode
camera2.SetActive(false); //The third person camera is disabled
camera3.SetActive(false); //The rear view camera is disabled
camera4.SetActive(true); //The rear view camera is disabled
camera5.SetActive(false); //The rear view camera is disabled
camera6.SetActive(false); //The rear view camera is disabled
}
if (Input.GetKey(KeyCode.Alpha5)) //If the button is pressed
{
camera1.SetActive(false); //The camera is changed to first person mode
camera2.SetActive(false); //The third person camera is disabled
camera3.SetActive(false); //The rear view camera is disabled
camera4.SetActive(false); //The rear view camera is disabled
camera5.SetActive(true); //The rear view camera is disabled
camera6.SetActive(false); //The rear view camera is disabled
}
if (Input.GetKey(KeyCode.Alpha6)) //If the button is pressed
{
camera1.SetActive(false); //The camera is changed to first person mode
camera2.SetActive(false); //The third person camera is disabled
camera3.SetActive(false); //The rear view camera is disabled
camera4.SetActive(false); //The rear view camera is disabled
camera5.SetActive(false); //The rear view camera is disabled
camera6.SetActive(true); //The rear view camera is disabled
}
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using TMPro;
public class JadePieceCollisions : MonoBehaviour {
[SerializeField] int pointValue; //The point value for the resource
public TMP_Text scoreText; //The score within the HUD
public TMP_Text lifeText; //The score within the HUD
private int theScore = 0; //The score at the start of the level
private int totalScore; //The players total score
private int lifeCount = 3;
[SerializeField] private float turnSpeed = 30f;
void Update()
{
transform.Rotate(Time.deltaTime * turnSpeed * Vector3.left);
}
void OnTriggerEnter(Collider collision) //A collision is detected
{
GameObject otherObject = collision.gameObject;
scoreTracker myTracker = otherObject.GetComponent<scoreTracker>(); //The score tracker is located
if (myTracker != null)
{
Destroy(gameObject); //The resource itself is destroyed
totalScore += pointValue; //The total score is equated
scoreText.text = totalScore.ToString(); //The score is converted in a way that it can be displayed in the HUD
if(totalScore >= 100)
{
lifeCount +=1;
}
}
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using TMPro;
public class boss : MonoBehaviour {
public int maxBossHealth = 100; // The players starting health
public int currentBossHealth; //the players current health
public bossHealth bossHealthBar; //The health bar within the HUD
public AudioSource BGM;
public static bool GameIsCompleted = false; //The game over conditions
public GameObject gameCompletionCutscene; //the game over screen
public GameObject hudUI; //The HUD
// Start is called before the first frame update
void Start()
{
currentBossHealth = maxBossHealth; //Health is set to maximum at the start
bossHealthBar.SetMaxBossHealth(maxBossHealth); //Health bar fill is also set to maximum
}
void Update()
{
if (Input.GetKeyDown(KeyCode.N)) //The space button is pressed
{
takeDamage(5); //Health is lost (testing purposes)
}
if (currentBossHealth <= 0) //Health reaches zero
{
GameCompleted(); //The game is lost
}
}
void takeDamage(int damage) //Function for taking damage
{
currentBossHealth -= damage; //The health is decreased by the amount of damage taken
bossHealthBar.SetBossHealth(currentBossHealth); //The healthbar also decreases
}
void GameCompleted() //The function for when the game over conditions are set
{
gameCompletionCutscene.SetActive(true); //The game over screen is displayed
hudUI.SetActive(false); // The HUD is disabled
BGM.Stop();
GameIsCompleted = true; //The game is lost
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using TMPro;
public class Enemy : MonoBehaviour {
public int maxEnemyHealth = 100; // The players starting health
public int currentEnemyHealth; //the players current health
public enemyHealth enemyHealthBar; //The health bar within the HUD
// Start is called before the first frame update
void Start()
{
currentEnemyHealth = maxEnemyHealth; //Health is set to maximum at the start
enemyHealthBar.SetMaxEnemyHealth(maxEnemyHealth); //Health bar fill is also set to maximum
}
private void OnTriggerEnter(Collider other)
{
if (other.gameObject.CompareTag("Ice"))
{
takeDamage(20); //Health is lost (testing purposes)
}
if (currentEnemyHealth <= 0) //Health reaches zero
{
Destroy(gameObject); //The game is lost
}
}
void takeDamage(int damage) //Function for taking damage
{
currentEnemyHealth -= damage; //The health is decreased by the amount of damage taken
enemyHealthBar.SetEnemyHealth(currentEnemyHealth); //The healthbar also decreases
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.AI;
public class enemyAfter : MonoBehaviour {
GameObject player;
NavMeshAgent agent;
[SerializeField] LayerMask groundLayer, playerLayer;
//patrol
Vector3 destPoint;
bool walkpointSet;
[SerializeField] float range;
//state change
[SerializeField] float sightRange, attackRange;
bool playerInSight, playerInAttackRange;
[SerializeField]
float _moveSpeed = 15.0f;
// Use this for initialization
void Start()
{
agent = GetComponent<NavMeshAgent>();
player = GameObject.Find("Player");
}
// Update is called once per frame
void Update()
{
playerInSight = Physics.CheckSphere(transform.position, sightRange, playerLayer);
playerInAttackRange = Physics.CheckSphere(transform.position, attackRange, playerLayer);
if(!playerInSight && !playerInAttackRange) Patrol();
if (playerInSight && !playerInAttackRange) Chase();
if (playerInSight && playerInAttackRange) Attack();
}
void Chase()
{
agent.SetDestination(player.transform.position);
}
void Attack()
{
}
void Patrol()
{
if (!walkpointSet) SearchForDest();
if (walkpointSet) agent.SetDestination(destPoint);
if (Vector3.Distance(transform.position, destPoint) < 10) walkpointSet = false;
}
void SearchForDest()
{
float z = Random.Range(-range, range);
float x = Random.Range(-range, range);
destPoint = new Vector3(transform.position.x + x, transform.position.y, transform.position.z + z);
if (Physics.Raycast(destPoint, Vector3.down, groundLayer))
{
walkpointSet = true;
}
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class floatingHealthBar : MonoBehaviour {
[SerializeField] private Slider slider;
public void UpdateHealthBar(float currentEnemyHealth, float maxEnemyHealth)
{
slider.value = currentEnemyHealth / maxEnemyHealth;
}
// Update is called once per frame
void Update()
{
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class bossHealth : MonoBehaviour {
public Slider slider; //The health bar
public Gradient gradient; //Health bar gradient
public Image fill; //The amount of healh within th bar
public void SetMaxBossHealth(int bossHealth) //The starting helath value (100%)
{
slider.maxValue = bossHealth; //The max health is set
slider.value = bossHealth; //The health value within the slider
fill.color = gradient.Evaluate(1f); //The gradient of the health bar
}
public void SetBossHealth(int bossHealth)
{
slider.value = bossHealth; //The health value within the slider
fill.color = gradient.Evaluate(slider.normalizedValue); //The gradient of the health bar
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class chiRefill : MonoBehaviour {
public int maxChi = 100; //The starting chi value
private int currentChi; //The current chi value
public energyBar chiBar; //The chi bar
void Start()
{
currentChi = maxChi; //the starting chi bar is set to the maximum energy bar
chiBar.SetMaxEnergy(maxChi);
}
void OnTriggerEnter(Collider collision) //A collision is detected
{
currentChi = maxChi; //The players health at the start
chiBar.SetMaxEnergy(maxChi);
chiBar.SetEnergy(maxChi); //The bar is set to maximum health
GameObject otherObject = collision.gameObject;
Destroy(gameObject); //the resource is destroyed when collided with
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class enemyHealth : MonoBehaviour {
public Slider slider; //The health bar
public Gradient gradient; //Health bar gradient
public Image fill; //The amount of healh within th bar
public void SetMaxEnemyHealth(int enemyHealth) //The starting helath value (100%)
{
slider.maxValue = enemyHealth; //The max health is set
slider.value = enemyHealth; //The health value within the slider
fill.color = gradient.Evaluate(1f); //The gradient of the health bar
}
public void SetEnemyHealth(int enemyHealth)
{
slider.value = enemyHealth; //The health value within the slider
fill.color = gradient.Evaluate(slider.normalizedValue); //The gradient of the health bar
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class energyBar : MonoBehaviour {
public Slider slider; //The energy bar
public Gradient gradient; //the energy bar gradient
public Image fill; //The amount of energy within the bar
public void SetMaxEnergy(int energy) //The starting energy level (100%)
{
slider.maxValue = energy; //The max energy level is set
slider.value = energy; //The energy value within the slider
fill.color = gradient.Evaluate(1f); //The gradient of the energy bar
}
public void SetEnergy(int energy)
{
slider.value = energy; //The energy value within the slider
fill.color = gradient.Evaluate(slider.normalizedValue);//The gradient of the energy bar
} }
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using TMPro;
public class halfHealthRefill : MonoBehaviour {
public int maxHealth = 50; //The players maximum health
public int currentHealth; //The players current health
public healthBar healthBar; //The health bar itself
void Start()
{
currentHealth = maxHealth; //The players health at the start
healthBar.SetMaxHealth(maxHealth);
healthBar.SetHealth(maxHealth); //The bar is set to maximum health
}
void OnTriggerEnter(Collider collision) //A collision is detected
{
currentHealth = maxHealth / 2; //The players health at the start
healthBar.SetMaxHealth(maxHealth / 2);
healthBar.SetHealth(maxHealth / 2); //The bar is set to maximum health
GameObject otherObject = collision.gameObject;
Destroy(gameObject); //the resource is destroyed when collided with
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class healthBar : MonoBehaviour {
public Slider slider; //The health bar
public Gradient gradient; //Health bar gradient
public Image fill; //The amount of healh within th bar
public void SetMaxHealth(int health) //The starting helath value (100%)
{
slider.maxValue = health; //The max health is set
slider.value = health; //The health value within the slider
fill.color = gradient.Evaluate(1f); //The gradient of the health bar
}
public void SetHealth(int health)
{
slider.value = health; //The health value within the slider
fill.color = gradient.Evaluate(slider.normalizedValue); //The gradient of the health bar
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using TMPro;
public class healthRefill : MonoBehaviour {
public int maxHealth = 100; //The players maximum health
private int currentHealth; //The players current health
public healthBar healthBar; //The health bar itself
void OnTriggerEnter(Collider collision) //A collision is detected
{
currentHealth = maxHealth; //The players health at the start
healthBar.SetMaxHealth(maxHealth);
healthBar.SetHealth(maxHealth); //The bar is set to maximum health
GameObject otherObject = collision.gameObject;
Destroy(gameObject); //the resource is destroyed when collided with
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using TMPro;
public class lifeManager : MonoBehaviour {
public TMP_Text lifeText;
public int lifeCount;
void OnTriggerEnter(Collider collision) //A collision is detected
{
GameObject otherObject = collision.gameObject;
lifeTracker myTracker = otherObject.GetComponent<lifeTracker>(); //The life tracker is located
if (myTracker != null)
{
Destroy(gameObject);
lifeCount = lifeCount + 1;
lifeText.text = lifeCount.ToString(); //The additional life is converted in a way that it can be displayed in the HUD
}
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class lifeTracker : MonoBehaviour {
[SerializeField] private int life = 3;
public int getLife()
{
return life; //the players number of lives
}
// Update is called once per frame
public void setLife(int newLifeValue)
{
life = newLifeValue;
}
public void incrementLife(int lifeToAdd)
{
life += lifeToAdd; //The number of lives is updated
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class scoreTracker : MonoBehaviour {
[SerializeField] private int score = 0; //The value of points that is assigned to the resource
public int getScore()
{
return score; //The score is shown to the player
}
// Update is called once per frame
public void setScore(int newScoreValue)
{
score = newScoreValue; //The score is shown to the player
}
public void incrementScore(int amountToAdd)
{
score += amountToAdd; //The score is updated
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class earthquake : MonoBehaviour {
public float timeBetweenQuakes = 30; //The time between each individual earthquake
public float timeForQuakes = 15; //The time that the earthquakes are active for
public GameObject palace; //The boss level pagoda
Animator shake;
Animator still;
// Start is called before the first frame update
public void Update()
{
if (timeBetweenQuakes > 0)
{
StartCoroutine(Stable());
}
if (timeBetweenQuakes <= 0)
{
StartCoroutine(EarthquakeEffect());
}
if (timeForQuakes <= 0)
{
StartCoroutine(Stable());
}
}
IEnumerator EarthquakeEffect()
{
timeForQuakes -= Time.deltaTime;
palace.GetComponent<Animator>().Play("Earthquake");
palace.GetComponent<Animator>().Play("Slow Meteors");
yield return new WaitForSeconds(15);
timeBetweenQuakes = 30;
}
IEnumerator Stable()
{
timeBetweenQuakes -= Time.deltaTime;
palace.GetComponent<Animator>().Play("Stable");
yield return new WaitForSeconds(1);
timeForQuakes = 15;
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
public class LevelManager : MonoBehaviour {
public string menuScene;
public string levelScene;
public string bossScene;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
}
public void MenuScene()
{
SceneManager.LoadScene(menuScene);
}
public void LevelScene()
{
SceneManager.LoadScene(levelScene);
}
public void BossScene()
{
SceneManager.LoadScene(bossScene);
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class slowMeteors : MonoBehaviour {
public float timeBetweenQuakes = 30; //The time between each individual earthquake
public float timeForQuakes = 15; //The time that the earthquakes are active for
public GameObject meteors; //The boss level pagoda
Animator shake;
Animator still;
// Start is called before the first frame update
public void Update()
{
if (timeBetweenQuakes > 0)
{
StartCoroutine(Stable());
}
if (timeBetweenQuakes <= 0)
{
StartCoroutine(SlowMeteors());
}
if (timeForQuakes <= 0)
{
StartCoroutine(Stable());
}
}
IEnumerator SlowMeteors()
{
timeForQuakes -= Time.deltaTime;
meteors.GetComponent<Animator>().Play("Slow Meteors");
yield return new WaitForSeconds(15);
timeBetweenQuakes = 30;
}
IEnumerator Stable()
{
timeBetweenQuakes -= Time.deltaTime;
meteors.GetComponent<Animator>().Play("NoMeteors");
yield return new WaitForSeconds(1);
timeForQuakes = 15;
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class endGoal : MonoBehaviour
{
public GameObject winnerScreenUI; //The congratulations screen
public GameObject hudUI; //The HUD screen
public GameObject thePlayer; //The player character needed to the collision detection
public static bool GameIsWon = false; //The condition required for the game to be won
void OnTriggerEnter(Collider collision) //A collision is detected
{
winnerScreenUI.SetActive(true); //The win screen is shown
hudUI.SetActive(false); //The HUD is disabled
Time.timeScale = 0f; //The game is paused/stopped
GameIsWon = true; //The game is won
GameObject otherObject = collision.gameObject;
Destroy(gameObject); //the resource is destroyed when collided with
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
public class gameOverScreen : MonoBehaviour {
public GameObject gameOverScreenUI; //The game over screen
public void RestartGame() //The game is restarted
{
SceneManager.LoadScene("Level One"); //Level One is reloaded
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class GameQuit : MonoBehaviour {
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
}
public void QuitGame() //The game is stopped
{
Application.Quit();
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
public class LevelBegin: MonoBehaviour {
public GameObject videoScreen;
public GameObject hudUI; //the HUD
public GameObject BGM;
public GameObject player; //The player object
public GameObject camera; //The first person camera for the first vehicle
void Start()
{
Time.timeScale = 0f; // The scene is paused
}
public void GameStart() //The first vehicle is chosen
{
videoScreen.SetActive(false);
hudUI.SetActive(true); //the HUD is displayed
BGM.SetActive(true);
player.SetActive(true); //The player object
Time.timeScale = 1f; //The scene starts
camera.SetActive(true);
}
public void LoadMenu() //The menu is loaded
{
Time.timeScale = 1f; //The scene is unpaused
SceneManager.LoadScene("Main Menu"); //The main menu is loaded
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
public class pauseMenu : MonoBehaviour {
public static bool GameIsPaused = false; //The pause conditions
public GameObject pauseMenuUI; //The pause menu
public GameObject hudMenuUI; //The heads up display menu
public GameObject controlsMenuUI; //The controls menu
public GameObject settingsMenuUI; //The settings menu
public GameObject hudUI; //The HUD screen
// Update is called once per frame
void Update()
{
if (Input.GetKeyDown(KeyCode.Escape)) //The escape button is pressed
{
if (GameIsPaused) //The game is currently paused
{
Resume(); //The game resumes
}
else
{
Pause(); //The game is paused if the game is currently running
}
}
}
public void Resume() //The resume game button function
{
pauseMenuUI.SetActive(false); //The pause menu is disabled
hudMenuUI.SetActive(false); //The hud menu is disabled
settingsMenuUI.SetActive(false); //The settings menu is disabled
controlsMenuUI.SetActive(false); //The controls menu is disabled
hudUI.SetActive(true); //The HUD is displayed once more
Time.timeScale = 1f; //The scene resumes
GameIsPaused = false; //The game is currently unpaused
}
void Pause() //The pause game button function
{
pauseMenuUI.SetActive(true); //The pause menu is displayed
hudUI.SetActive(false); //The HUD is disabled
Time.timeScale = 0f; // The scene is paused
GameIsPaused = true; //The game is currently paused
}
public void LoadMenu() //The load menu button function
{
Time.timeScale = 1f;
SceneManager.LoadScene("Main Menu");
}
public void RestartGame() //The Restart game button function
{
SceneManager.LoadScene("Level One"); //The level is restarted
}
public void QuitGame() //The quit game button function
{
Debug.Log("Quitting Game");
Application.Quit(); //The game is quit
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using TMPro;
public class player : MonoBehaviour {
public int maxHealth = 100; // The players starting health
public int currentHealth; //the players current health
public healthBar healthBar; //The health bar within the HUD
public int maxEnergy = 100; //The players starting energy
public int currentEnergy; //The players current energy
public energyBar energyBar; //The energy bar within the HUD
public static bool GameIsOver = false; //The game over conditions
public GameObject gameOverScreenUI; //the game over screen
public GameObject hudUI; //The HUD
// Start is called before the first frame update
void Start()
{
currentHealth = maxHealth; //Health is set to maximum at the start
healthBar.SetMaxHealth(maxHealth); //Health bar fill is also set to maximum
currentEnergy = maxEnergy; //Energy is set to maximum at the start
energyBar.SetMaxEnergy(maxEnergy); //Energy bar fill is also set to maximum
}
void Update()
{
if (Input.GetKeyDown(KeyCode.Space)) //The space button is pressed
{
takeDamage(10); //Health is lost (testing purposes)
loseEnergy(10); //Energy is lost (testing purposes)
}
if (currentHealth <= 0) //Health reaches zero
{
GameOver(); //The game is lost
}
}
void OnCollisionEnter(Collision collision)
{
Debug.Log("Collision detected" + collision.gameObject.name);
}
void takeDamage(int damage) //Function for taking damage
{
currentHealth -= damage; //The health is decreased by the amount of damage taken
healthBar.SetHealth(currentHealth); //The healthbar also decreases
}
void loseEnergy(int power) //Function for losing energy
{
currentEnergy -= power; //The energy us decreased by the amount of power used
energyBar.SetEnergy(currentEnergy); //The energy bar also decreases
}
void GameOver() //The function for when the game over conditions are set
{
gameOverScreenUI.SetActive(true); //The game over screen is displayed
hudUI.SetActive(false); // The HUD is disabled
GameIsOver = true; //The game is lost
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class playerControls : MonoBehaviour {
[SerializeField] private float _moveSpeed = 2f; //The speed the player is moving in
[SerializeField] private float _turnSpeed = 10f; //The speed the player turns in
public float jumpForce = 500;
private Rigidbody playerRb;
public bool isOnGround;
CharacterController _characterController; void Awake() => _characterController = GetComponent();
void Start()
{
playerRb = GetComponent<Rigidbody>();
}
// Update is called once per frame
void Update()
{
float horizontal = Input.GetAxis("Mouse X");
transform.Rotate(horizontal * _turnSpeed * Vector3.up, Space.World);
float vertical = Input.GetAxis("Mouse Y");
transform.Rotate(vertical * _turnSpeed * Vector3.up, Space.World);
if (Input.GetKey(KeyCode.Q))
transform.Rotate(Time.deltaTime * _turnSpeed * Vector3.down); //turns player left
if (Input.GetKey(KeyCode.E))
transform.Rotate(Time.deltaTime * _turnSpeed * Vector3.up); //turns player right
if (Input.GetKey(KeyCode.D))
transform.position += Time.deltaTime * _moveSpeed * transform.right; //moves player right
if (Input.GetKey(KeyCode.A))
transform.position += Time.deltaTime * _moveSpeed * -transform.right; //moves player left
if (Input.GetKey(KeyCode.W))
transform.position += Time.deltaTime * _moveSpeed * transform.forward; //moves player forward
if (Input.GetKey(KeyCode.S))
transform.position += Time.deltaTime * _moveSpeed * -transform.forward; //moves player back
if (Input.GetKey(KeyCode.C))
transform.position += Time.deltaTime * _moveSpeed * -transform.up; //moves player Up
if (Input.GetKey(KeyCode.Z))
transform.position += Time.deltaTime * _moveSpeed * transform.up; //moves player Down
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class shootingChiBlast : MonoBehaviour {
public GameObject chiSpawn; public Transform spawnPoint; public GameObject chiBlast; //The bog standand chi blast
public GameObject fireSpawn; public Transform spawnPoint2; public GameObject fireBlast; //The fire chi blast
public GameObject iceSpawn; public Transform spawnPoint3; public GameObject iceBlast; //The ice chi blast
public GameObject windSpawn; public Transform spawnPoint4; public GameObject windBlast; //The wind chi blast
public GameObject earthSpawn; public Transform spawnPoint5; public GameObject earthBlast; //The earth chi blast
public GameObject lightningSpawn; public Transform spawnPoint6; public GameObject lightningBlast; //The lightning chi blast
public float speed = 300; //The speed of the projectile
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
if (Input.GetMouseButtonDown(0))
{
ShootChi(); ShootFire(); ShootIce();
ShootWind(); ShootEarth(); ShootLightning();
}
}
void OnTriggerEnter(Collider other) //A collision is detected
{
if (other.gameObject.CompareTag("Fire"))
{
Destroy(other.gameObject);
chiBlast.SetActive(false);
fireBlast.SetActive(true);
iceBlast.SetActive(false);
windBlast.SetActive(false);
earthBlast.SetActive(false);
lightningBlast.SetActive(false);
StartCoroutine(Chi());
}
if (other.gameObject.CompareTag("Ice"))
{
Destroy(other.gameObject);
chiBlast.SetActive(false);
fireBlast.SetActive(false);
iceBlast.SetActive(true);
windBlast.SetActive(false);
earthBlast.SetActive(false);
lightningBlast.SetActive(false);
StartCoroutine(Chi());
}
if (other.gameObject.CompareTag("Wind"))
{
Destroy(other.gameObject);
chiBlast.SetActive(false);
fireBlast.SetActive(false);
iceBlast.SetActive(false);
windBlast.SetActive(true);
earthBlast.SetActive(false);
lightningBlast.SetActive(false);
StartCoroutine(Chi());
}
if (other.gameObject.CompareTag("Earth"))
{
Destroy(other.gameObject);
chiBlast.SetActive(false);
fireBlast.SetActive(false);
iceBlast.SetActive(false);
windBlast.SetActive(false);
earthBlast.SetActive(true);
lightningBlast.SetActive(false);
StartCoroutine(Chi());
}
if (other.gameObject.CompareTag("Lightning"))
{
Destroy(other.gameObject);
chiBlast.SetActive(false);
fireBlast.SetActive(false);
iceBlast.SetActive(false);
windBlast.SetActive(false);
earthBlast.SetActive(false);
lightningBlast.SetActive(true);
StartCoroutine(Chi());
}
}
public void ShootChi() //The function for the standard chi blast
{
GameObject cb = Instantiate(chiBlast, spawnPoint.position, chiBlast.transform.rotation); //The projectile prefab is instantiated at the spawnpoint
Rigidbody rig = cb.GetComponent<Rigidbody>(); //The rigidbody for the projectile is accounted for
transform.position += Time.deltaTime * speed * transform.forward; //The projectile fires forward
rig.AddForce(spawnPoint.forward * speed, ForceMode.Impulse);
}
public void ShootFire() //The function for the standard chi blast {
GameObject cb = Instantiate(fireBlast, spawnPoint2.position, fireBlast.transform.rotation); //The projectile prefab is instantiated at the spawnpoint
Rigidbody rig = cb.GetComponent<Rigidbody>(); //The rigidbody for the projectile is accounted for
transform.position += Time.deltaTime * speed * transform.forward; //The projectile fires forward
rig.AddForce(spawnPoint2.forward * speed, ForceMode.Impulse);
}
public void ShootIce() //The function for the standard chi blast {
GameObject cb = Instantiate(iceBlast, spawnPoint3.position, iceBlast.transform.rotation); //The projectile prefab is instantiated at the spawnpoint
Rigidbody rig = cb.GetComponent<Rigidbody>(); //The rigidbody for the projectile is accounted for
transform.position += Time.deltaTime * speed * transform.forward; //The projectile fires forward
rig.AddForce(spawnPoint3.forward * speed, ForceMode.Impulse);
}
public void ShootWind() //The function for the standard chi blast {
GameObject cb = Instantiate(windBlast, spawnPoint4.position, windBlast.transform.rotation); //The projectile prefab is instantiated at the spawnpoint
Rigidbody rig = cb.GetComponent<Rigidbody>(); //The rigidbody for the projectile is accounted for
transform.position += Time.deltaTime * speed * transform.forward; //The projectile fires forward
rig.AddForce(spawnPoint4.forward * speed, ForceMode.Impulse);
}
public void ShootEarth() //The function for the standard chi blast {
GameObject cb = Instantiate(earthBlast, spawnPoint5.position, earthBlast.transform.rotation); //The projectile prefab is instantiated at the spawnpoint
Rigidbody rig = cb.GetComponent<Rigidbody>(); //The rigidbody for the projectile is accounted for
transform.position += Time.deltaTime * speed * transform.forward; //The projectile fires forward
rig.AddForce(spawnPoint5.forward * speed, ForceMode.Impulse);
}
public void ShootLightning() //The function for the standard chi blast {
GameObject cb = Instantiate(lightningBlast, spawnPoint6.position, lightningBlast.transform.rotation); //The projectile prefab is instantiated at the spawnpoint
Rigidbody rig = cb.GetComponent<Rigidbody>(); //The rigidbody for the projectile is accounted for
transform.position += Time.deltaTime * speed * transform.forward; //The projectile fires forward
rig.AddForce(spawnPoint6.forward * speed, ForceMode.Impulse);
}
IEnumerator Chi() { yield return new WaitForSeconds(20); chiBlast.SetActive(true); fireBlast.SetActive(false); iceBlast.SetActive(false); windBlast.SetActive(false); earthBlast.SetActive(false); lightningBlast.SetActive(false); }
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Spin : MonoBehaviour {
public Vector3 angle;
public float speed = 5;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
transform.Rotate(angle * speed * Time.deltaTime);
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using TMPro;
public class graphicsSelector : MonoBehaviour {
public TMP_Dropdown graphicsDropdown; //The dropdown list
public void setQuality(int qualityIndex) //The game quality
{
QualitySettings.SetQualityLevel(qualityIndex); //The game quality is set
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using TMPro;
public class resolutionSelector : MonoBehaviour {
public TMP_Dropdown resolutionDropdown; //The dropdown list
Resolution[] resolutions; //The contents of the dropdown list
// Start is called before the first frame update
void Start()
{
resolutions = Screen.resolutions; //The resolution is set
resolutionDropdown.ClearOptions(); //The other options are cleared
List<string> options = new List<string>();
int currentResolutionIndex = 0;
for (int i = 0; i < resolutions.Length; i++)
{
string option = resolutions[i].width + " x " + resolutions[i].height; //The contents of each dropdown option
options.Add(option); //The contents are added to the list
if (resolutions[i].width == Screen.currentResolution.width && resolutions[i].height == Screen.currentResolution.height)
{
currentResolutionIndex = 1;
}
}
resolutionDropdown.AddOptions(options); //The contents are added to the list
resolutionDropdown.value = currentResolutionIndex;
resolutionDropdown.RefreshShownValue();
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class volumeManager : MonoBehaviour
{
public Slider volumeSlider; //The volume slided
// Start is called before the first frame update
void Start()
{
if (!PlayerPrefs.HasKey("musicVolume")) //The music volume
{
PlayerPrefs.SetFloat("musicVolume", 0);
Load(); //The volume is changed
}
else
{
Load();
}
}
public void ChangeVolume()
{
AudioListener.volume = volumeSlider.value; //The volume is changed
Save();//The volume is saved
}
private void Load()
{
volumeSlider.value = PlayerPrefs.GetFloat("musicVolume"); //The volume is loaded
}
private void Save()
{
PlayerPrefs.SetFloat("musicVolume", volumeSlider.value);
}
}