diff --git a/UnityFolderScripts/AIScripts.meta b/UnityFolderScripts/AIScripts.meta new file mode 100644 index 0000000..1f7f735 --- /dev/null +++ b/UnityFolderScripts/AIScripts.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: a7ed0caa1a5042d4c821035867740931 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/UnityFolderScripts/AIScripts/AI Damage.meta b/UnityFolderScripts/AIScripts/AI Damage.meta new file mode 100644 index 0000000..874cec4 --- /dev/null +++ b/UnityFolderScripts/AIScripts/AI Damage.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: cb4b350e53ab9fd43aae3c45ef79bcd1 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/UnityFolderScripts/AIScripts/AI Damage/MonsterCarDamage.cs b/UnityFolderScripts/AIScripts/AI Damage/MonsterCarDamage.cs new file mode 100644 index 0000000..17100a7 --- /dev/null +++ b/UnityFolderScripts/AIScripts/AI Damage/MonsterCarDamage.cs @@ -0,0 +1,14 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +public class MonsterCarDamage : MonoBehaviour +{ + public void OnCollisionEnter2D(Collision2D other) //if we collide with police car + { + if (other.gameObject.tag == "Player") + { + MonsterCarHealthManager.instance.DamageMonsterCar(); + } + } +} diff --git a/UnityFolderScripts/AIScripts/AI Damage/MonsterCarDamage.cs.meta b/UnityFolderScripts/AIScripts/AI Damage/MonsterCarDamage.cs.meta new file mode 100644 index 0000000..c748aeb --- /dev/null +++ b/UnityFolderScripts/AIScripts/AI Damage/MonsterCarDamage.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: f45299cd1438dc242a7c9de0d21065f0 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/UnityFolderScripts/AIScripts/AI Health.meta b/UnityFolderScripts/AIScripts/AI Health.meta new file mode 100644 index 0000000..6758dc2 --- /dev/null +++ b/UnityFolderScripts/AIScripts/AI Health.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 4102a69fac7854d45badd06ba3b80334 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/UnityFolderScripts/AIScripts/AI Health/MonsterCarHealthManager.cs b/UnityFolderScripts/AIScripts/AI Health/MonsterCarHealthManager.cs new file mode 100644 index 0000000..920423d --- /dev/null +++ b/UnityFolderScripts/AIScripts/AI Health/MonsterCarHealthManager.cs @@ -0,0 +1,37 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +public class MonsterCarHealthManager : MonoBehaviour +{ + + public static MonsterCarHealthManager instance; + public int currentHealth; + public int maxHealth; + public GameObject explosion; + public AudioSource carExplosion; + public void Awake() + { + instance = this; + } + private void Start() + { + currentHealth = maxHealth; + } + public void DamageMonsterCar() + { + currentHealth--; + if (currentHealth <= 0) + { + Instantiate(explosion, transform.position, transform.rotation); + gameObject.SetActive(false); + carExplosion.Play(); + GameManager.instance.KillMonsterCar(); + } + } + public void Respawn() + { + gameObject.SetActive(true); + currentHealth = maxHealth + 1; + } +} diff --git a/UnityFolderScripts/AIScripts/AI Health/MonsterCarHealthManager.cs.meta b/UnityFolderScripts/AIScripts/AI Health/MonsterCarHealthManager.cs.meta new file mode 100644 index 0000000..b4a09c3 --- /dev/null +++ b/UnityFolderScripts/AIScripts/AI Health/MonsterCarHealthManager.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 54b8f758fc58a3f49baf777c345e7818 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/UnityFolderScripts/AIScripts/AICars.cs b/UnityFolderScripts/AIScripts/AICars.cs new file mode 100644 index 0000000..3b0f5b9 --- /dev/null +++ b/UnityFolderScripts/AIScripts/AICars.cs @@ -0,0 +1,66 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +public class AICars : MonoBehaviour +{ + public float accelerator; + public float turnpower = 1; + public float turnspeed = 4; + Rigidbody2D rb; + internal bool isAIMovement; + private float friction = 1.5f; + private float currentSpeed; + private Vector2 curSpeed; + float currentAcc; + private bool isMoving; + + public AudioSource engine; + public float maxEngineSound; + // Start is called before the first frame update + void Start() + { + rb = GetComponent(); + currentAcc = accelerator; + } + + private void Update() + { + if (engine != null) + { + engine.pitch=1f+((rb.velocity.magnitude / maxEngineSound) * 3f) ; + } + } + + // Update is called once per frame + void FixedUpdate() + { + if (isMoving) + { + rb.AddForce(transform.up * currentAcc); + } + if (!isMoving) + { + rb.drag = friction * 2; + } + } + + public void Movement(string turning,bool isPaddlePressed) + { + if (turning == "left") + { + transform.Rotate(Vector3.forward * (currentSpeed + currentSpeed)); + } + else if (turning == "right") + { + transform.Rotate(Vector3.forward * -(currentSpeed + currentSpeed)); + } + if (isPaddlePressed) + { + isMoving = true; + } + + currentSpeed = curSpeed.magnitude / turnspeed; + curSpeed = new Vector2(rb.velocity.x, rb.velocity.y); + } +} diff --git a/UnityFolderScripts/AIScripts/AICars.cs.meta b/UnityFolderScripts/AIScripts/AICars.cs.meta new file mode 100644 index 0000000..6eed90c --- /dev/null +++ b/UnityFolderScripts/AIScripts/AICars.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 005059227a4024942830a60bf2618b95 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/UnityFolderScripts/AIScripts/AIMovement.cs b/UnityFolderScripts/AIScripts/AIMovement.cs new file mode 100644 index 0000000..52b6be8 --- /dev/null +++ b/UnityFolderScripts/AIScripts/AIMovement.cs @@ -0,0 +1,74 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +public class AIMovement : MonoBehaviour +{ + List routes; + private Vector3 nextPoint; + public GameObject AIPathHolder; + private bool isAccPressed = false; + AICars driver; + int totalWayPoints; + int currentIndex; + private bool nextPos; + private string turning; + AIPathway wayPoint; + internal Transform currentWayPoint; + + // Start is called before the first frame update + void Start() + { + driver = GetComponent(); + if (AIPathHolder != null) + { + driver.isAIMovement = true; + wayPoint = AIPathHolder.GetComponent(); + routes = wayPoint.route; + currentIndex = 0; + totalWayPoints = routes.Count; + currentWayPoint = routes[0].transform; + } + } + + // Update is called once per frame + void Update() + { + if (!nextPos) + { + nextPoint = currentWayPoint.position; + nextPos = true; + } + Vector3 relativeVector = transform.InverseTransformPoint(nextPoint); + turning = null; + + if (relativeVector.x > 0.5f) + { + turning = "right"; + } + else if (relativeVector.x < -0.5f) + { + turning = "left"; + } + float dist = Vector2.Distance(transform.position, nextPoint); + isAccPressed = true; + if (dist < 2) + { + currentIndex++; + if (currentIndex >= totalWayPoints) + { + currentIndex = 0; + } + currentWayPoint = routes[currentIndex].transform; + nextPos = false; + } + } + + private void FixedUpdate() + { + if (driver.isAIMovement) + { + driver.Movement(turning, isAccPressed); + } + } +} diff --git a/UnityFolderScripts/AIScripts/AIMovement.cs.meta b/UnityFolderScripts/AIScripts/AIMovement.cs.meta new file mode 100644 index 0000000..967140f --- /dev/null +++ b/UnityFolderScripts/AIScripts/AIMovement.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 5ea57d40cbd0a9d4ab9b9c294032923d +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/UnityFolderScripts/AIScripts/AIPathway.cs b/UnityFolderScripts/AIScripts/AIPathway.cs new file mode 100644 index 0000000..135e163 --- /dev/null +++ b/UnityFolderScripts/AIScripts/AIPathway.cs @@ -0,0 +1,59 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; +using UnityEditor; + +[ExecuteInEditMode] +public class AIPathway : MonoBehaviour +{ + public List route; + public bool drawLine = true; + private void Awake() + { + if (route == null) + { + route = new List(); + } + } + + // Update is called once per frame + void Update() + { +#if UNITY_EDITOR + if (!EditorApplication.isPlaying) + { + if (route == null) + { + route = new List(); + } + route.Clear(); + foreach (Transform node in transform) + { + route.Add(node.gameObject); + } + } + if (route != null && route.Count > 1) + { + if (drawLine)//for checkbox + { + DrawLine(); + } + } +#endif + } + private void DrawLine() + { + int index = 0; + Vector3 lastPos = route[index].transform.position; + for (int i = 0; i < route.Count; i++) + { + Debug.DrawLine(lastPos, route[index].transform.position); + lastPos = route[index].transform.position; + if (index == route.Count - 1) + { + Debug.DrawLine(lastPos, route[0].transform.position); + } + index++; + } + } +} diff --git a/UnityFolderScripts/AIScripts/AIPathway.cs.meta b/UnityFolderScripts/AIScripts/AIPathway.cs.meta new file mode 100644 index 0000000..f30f273 --- /dev/null +++ b/UnityFolderScripts/AIScripts/AIPathway.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 5ba2b2babd86be241b18a227f9c5d145 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/UnityFolderScripts/AIScripts/AIVictoryTriggers.meta b/UnityFolderScripts/AIScripts/AIVictoryTriggers.meta new file mode 100644 index 0000000..9c3fbc8 --- /dev/null +++ b/UnityFolderScripts/AIScripts/AIVictoryTriggers.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 97d134dd243d32441a718f3a57fe8e49 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/UnityFolderScripts/AIScripts/AIVictoryTriggers/AIVictoryFullMonsterTruck.cs b/UnityFolderScripts/AIScripts/AIVictoryTriggers/AIVictoryFullMonsterTruck.cs new file mode 100644 index 0000000..5e83a8f --- /dev/null +++ b/UnityFolderScripts/AIScripts/AIVictoryTriggers/AIVictoryFullMonsterTruck.cs @@ -0,0 +1,29 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; +using UnityEngine.SceneManagement; + +public class AIVictoryFullMonsterTruck : MonoBehaviour +{ + public int currentLap; + public int maxLap; + + // Start is called before the first frame update + void Start() + { + currentLap = maxLap; + } + private void OnTriggerEnter2D(Collider2D other) + { + if (other.tag == "FullMonsterCar") + { + currentLap--; + if (currentLap <= 0) + { + SceneManager.LoadScene("AIVictory"); + } + } + } + + +} diff --git a/UnityFolderScripts/AIScripts/AIVictoryTriggers/AIVictoryFullMonsterTruck.cs.meta b/UnityFolderScripts/AIScripts/AIVictoryTriggers/AIVictoryFullMonsterTruck.cs.meta new file mode 100644 index 0000000..8b61252 --- /dev/null +++ b/UnityFolderScripts/AIScripts/AIVictoryTriggers/AIVictoryFullMonsterTruck.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 5c3d1a1ef64d8344e9d7ab67617240b0 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/UnityFolderScripts/AIScripts/CopBulletDestroy.cs b/UnityFolderScripts/AIScripts/CopBulletDestroy.cs new file mode 100644 index 0000000..fc32ce6 --- /dev/null +++ b/UnityFolderScripts/AIScripts/CopBulletDestroy.cs @@ -0,0 +1,11 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +public class CopBulletDestroy : MonoBehaviour +{ + private void OnCollisionEnter2D(Collision2D collision) + { + Destroy(this.gameObject); + } +} diff --git a/UnityFolderScripts/AIScripts/CopBulletDestroy.cs.meta b/UnityFolderScripts/AIScripts/CopBulletDestroy.cs.meta new file mode 100644 index 0000000..6aaf34f --- /dev/null +++ b/UnityFolderScripts/AIScripts/CopBulletDestroy.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 20b6d0565160d03409903bf945687556 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/UnityFolderScripts/AIScripts/CopShoot.cs b/UnityFolderScripts/AIScripts/CopShoot.cs new file mode 100644 index 0000000..09f89e9 --- /dev/null +++ b/UnityFolderScripts/AIScripts/CopShoot.cs @@ -0,0 +1,68 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +public class CopShoot : MonoBehaviour +{ + public float radius; + bool located = false; + public Transform target; + Vector2 Direction; + public GameObject cop; + private float nextShot = 0; + public float fireRate; + public GameObject bullet; + public float force; + public Transform pointOfShot; + // Start is called before the first frame update + void Start() + { + + } + + // Update is called once per frame + void Update() + { + Vector2 targetPos = target.position; + Direction = targetPos - (Vector2)transform.position; + RaycastHit2D rayInfo = Physics2D.Raycast(transform.position, Direction, radius); + + if (rayInfo) + { + if (rayInfo.collider.gameObject.tag == "Player") + { + if (located == false) + { + located = true; + } + } + else + { + if (located == true) + { + located = false; + } + } + } + if (located) + { + cop.transform.up = Direction; + if (Time.time > nextShot) + { + nextShot = Time.time + 1 / fireRate; + ShootBullet(); + } + } + } + void ShootBullet() + { + GameObject BulletIns = Instantiate(bullet, pointOfShot.position, Quaternion.identity); + BulletIns.GetComponent().AddForce(Direction * force); + } + + private void OnDrawGizmosSelected() + { + Gizmos.color = Color.red; + Gizmos.DrawWireSphere(transform.position, radius); + } +} diff --git a/UnityFolderScripts/AIScripts/CopShoot.cs.meta b/UnityFolderScripts/AIScripts/CopShoot.cs.meta new file mode 100644 index 0000000..82a5fe9 --- /dev/null +++ b/UnityFolderScripts/AIScripts/CopShoot.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 16e299f9d4b4b654082471d0512d6d39 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/UnityFolderScripts/CallOut.cs b/UnityFolderScripts/CallOut.cs new file mode 100644 index 0000000..2053f37 --- /dev/null +++ b/UnityFolderScripts/CallOut.cs @@ -0,0 +1,13 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +public class CallOut : MonoBehaviour +{ + public AudioSource sound; + + public void OnTriggerEnter2D(Collider2D other) + { + sound.Play(); + } +} diff --git a/UnityFolderScripts/CallOut.cs.meta b/UnityFolderScripts/CallOut.cs.meta new file mode 100644 index 0000000..b783594 --- /dev/null +++ b/UnityFolderScripts/CallOut.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 1bfe3cba70ae39e4c84ff60ee51b4ae4 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/UnityFolderScripts/CameraFollow.cs b/UnityFolderScripts/CameraFollow.cs new file mode 100644 index 0000000..bd13318 --- /dev/null +++ b/UnityFolderScripts/CameraFollow.cs @@ -0,0 +1,14 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +public class CameraFollow : MonoBehaviour +{ + public Transform car; + + // Update is called once per frame + void Update() + { + transform.position = new Vector3(car.position.x, car.position.y, -10f); + } +} diff --git a/UnityFolderScripts/CameraFollow.cs.meta b/UnityFolderScripts/CameraFollow.cs.meta new file mode 100644 index 0000000..b5c5cce --- /dev/null +++ b/UnityFolderScripts/CameraFollow.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 3a4f2edc0a39aa64098207c66ddbddec +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/UnityFolderScripts/Cones.cs b/UnityFolderScripts/Cones.cs new file mode 100644 index 0000000..b8dd563 --- /dev/null +++ b/UnityFolderScripts/Cones.cs @@ -0,0 +1,28 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +public class Cones : MonoBehaviour +{ + public GameObject coneFallref = null; + public AudioSource coneSound = null; + + private void OnCollisionEnter2D(Collision2D collision) + { + if (collision.gameObject.CompareTag("Player")) + { + if (!coneSound.isPlaying) + { + coneSound.pitch = UnityEngine.Random.Range(1, 1.2f); + coneSound.Play(); + if (coneFallref != null) + { + GameObject coneFall = (GameObject)Instantiate(coneFallref); + coneFall.transform.position = transform.position; + coneFall.transform.rotation = transform.rotation; + Destroy(gameObject); + } + } + } + } +} diff --git a/UnityFolderScripts/Cones.cs.meta b/UnityFolderScripts/Cones.cs.meta new file mode 100644 index 0000000..d615da1 --- /dev/null +++ b/UnityFolderScripts/Cones.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 0fb0cb39842d1b04a8d678ed958c78c7 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/UnityFolderScripts/DamagePlayer.cs b/UnityFolderScripts/DamagePlayer.cs new file mode 100644 index 0000000..50f2c67 --- /dev/null +++ b/UnityFolderScripts/DamagePlayer.cs @@ -0,0 +1,14 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +public class DamagePlayer : MonoBehaviour +{ + public void OnCollisionEnter2D(Collision2D other) //if we collide with police car + { + if (other.gameObject.tag == "Player") + { + HealthManager.instance.DamagePlayer(); + } + } +} diff --git a/UnityFolderScripts/DamagePlayer.cs.meta b/UnityFolderScripts/DamagePlayer.cs.meta new file mode 100644 index 0000000..74dc61a --- /dev/null +++ b/UnityFolderScripts/DamagePlayer.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 62badc358971cd648a2c264e978a2d15 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/UnityFolderScripts/DelayStart.cs b/UnityFolderScripts/DelayStart.cs new file mode 100644 index 0000000..0c06a62 --- /dev/null +++ b/UnityFolderScripts/DelayStart.cs @@ -0,0 +1,27 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +public class DelayStart : MonoBehaviour +{ + public GameObject start; + public AudioSource go; + // Start is called before the first frame update + void Start() + { + StartCoroutine("StartUp"); + } + + IEnumerator StartUp() + { + Time.timeScale = 0;//freezes the screen + float pauseTime = Time.realtimeSinceStartup + 3f;//for 3 sec + go.Play(); + while (Time.realtimeSinceStartup < pauseTime) + { + yield return 0; + } + start.gameObject.SetActive(false);//animation off + Time.timeScale = 1; + } +} diff --git a/UnityFolderScripts/DelayStart.cs.meta b/UnityFolderScripts/DelayStart.cs.meta new file mode 100644 index 0000000..d4917d3 --- /dev/null +++ b/UnityFolderScripts/DelayStart.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: b6c77c82662ff4b4a897f65514e7f308 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/UnityFolderScripts/GameManager.cs b/UnityFolderScripts/GameManager.cs new file mode 100644 index 0000000..d36c11c --- /dev/null +++ b/UnityFolderScripts/GameManager.cs @@ -0,0 +1,93 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; +using UnityEngine.UI; +using UnityEngine.SceneManagement; +public class GameManager : MonoBehaviour +{ + public static GameManager instance; + public int currentLives = 3; + public float respawnTime = 2f; + + public GameObject pauseScreen; + public string levelLoad; + public bool isPaused; + + public AudioSource engine; + public AudioSource monsterTruck; + public AudioSource heli; + + public void Awake() + { + instance = this; + } + + private void Update() + { + if (Input.GetKeyDown(KeyCode.Escape)) + { + pauseUnpause(); + } + } + + public void pauseUnpause() + { + isPaused = !isPaused; + pauseScreen.SetActive(isPaused); + if (isPaused)//stop everything + { + Time.timeScale = 0f; + engine.Stop(); + monsterTruck.Stop(); + heli.Stop(); + + } + else + { + Time.timeScale = 1f; + engine.Play(); + monsterTruck.Play(); + heli.Play(); + } + } + + //menu + public void ExitRace() + { + Time.timeScale = 1f; + SceneManager.LoadScene(levelLoad); + } + //quit + public void QuitGame() + { + Application.Quit(); + Debug.Log("quit game"); + } + + public void KillPlayer() + { + currentLives--; + if (currentLives > 0) + { + StartCoroutine(RespawnCo()); + } + } + public IEnumerator RespawnCo() + { + yield return new WaitForSeconds(respawnTime); + HealthManager.instance.Respawn(); + } + public void KillMonsterCar() + { + currentLives--; + if (currentLives > 0) + { + StartCoroutine(RespawnMonsterCar()); + } + } + public IEnumerator RespawnMonsterCar() + { + yield return new WaitForSeconds(respawnTime); + MonsterCarHealthManager.instance.Respawn(); + } +} diff --git a/UnityFolderScripts/GameManager.cs.meta b/UnityFolderScripts/GameManager.cs.meta new file mode 100644 index 0000000..bf0a339 --- /dev/null +++ b/UnityFolderScripts/GameManager.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 5d914296908aac54dbd8a256736312d3 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/UnityFolderScripts/HalfwayTrigger.cs b/UnityFolderScripts/HalfwayTrigger.cs new file mode 100644 index 0000000..f14bbba --- /dev/null +++ b/UnityFolderScripts/HalfwayTrigger.cs @@ -0,0 +1,18 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +public class HalfwayTrigger : MonoBehaviour +{ + public GameObject halfWayTrig; + public GameObject lapCompleteTrig; + + private void OnTriggerEnter2D(Collider2D other) + { + if (other.tag == "Player") + { + lapCompleteTrig.SetActive(true); // Turn on the Trigger + halfWayTrig.SetActive(false); // Turn off the Trigger + } + } +} diff --git a/UnityFolderScripts/HalfwayTrigger.cs.meta b/UnityFolderScripts/HalfwayTrigger.cs.meta new file mode 100644 index 0000000..ee267c7 --- /dev/null +++ b/UnityFolderScripts/HalfwayTrigger.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 95e0e438986c0304b912b134c01b16c2 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/UnityFolderScripts/HealthManager.cs b/UnityFolderScripts/HealthManager.cs new file mode 100644 index 0000000..3d7937d --- /dev/null +++ b/UnityFolderScripts/HealthManager.cs @@ -0,0 +1,37 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +public class HealthManager : MonoBehaviour +{ + + public static HealthManager instance; + public int currentHealth; + public int maxHealth; + public GameObject explosion; + public AudioSource carExplosion; + public void Awake() + { + instance = this; + } + private void Start() + { + currentHealth = maxHealth; + } + public void DamagePlayer() + { + currentHealth--; + if (currentHealth <= 0) + { + Instantiate(explosion,transform.position, transform.rotation); + gameObject.SetActive(false); + carExplosion.Play(); + GameManager.instance.KillPlayer(); + } + } + public void Respawn() + { + gameObject.SetActive(true); + currentHealth = maxHealth+1; + } +} diff --git a/UnityFolderScripts/HealthManager.cs.meta b/UnityFolderScripts/HealthManager.cs.meta new file mode 100644 index 0000000..dc78964 --- /dev/null +++ b/UnityFolderScripts/HealthManager.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 28a09b5bf0b5bd646a05503edb37ac64 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/UnityFolderScripts/LapComplete.cs b/UnityFolderScripts/LapComplete.cs new file mode 100644 index 0000000..8e8deee --- /dev/null +++ b/UnityFolderScripts/LapComplete.cs @@ -0,0 +1,45 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; +using UnityEngine.UI; +public class LapComplete : MonoBehaviour +{ + public GameObject trackComplete; + public GameObject halfWay; + public GameObject minBest; + public GameObject secBest; + public GameObject milliBest; + + + public GameObject lapCounter; + public int lapsCom; + + private void OnTriggerEnter2D(Collider2D other) + { + lapsCom += 1; + if (LapTime.secCount <= 9) + { + secBest.GetComponent().text = "0" + LapTime.secCount + "."; + } + else + { + secBest.GetComponent().text = "" + LapTime.secCount + "."; + } + if (LapTime.minCount <= 9) + { + minBest.GetComponent().text = "0" + LapTime.minCount + "."; + } + else + { + minBest.GetComponent().text = "" + LapTime.minCount + "."; + } + milliBest.GetComponent().text = "" + LapTime.milliCount; + LapTime.minCount = 0; + LapTime.secCount = 0; + LapTime.milliCount = 0; + + lapCounter.GetComponent().text = "" + lapsCom; + halfWay.SetActive(true); + trackComplete.SetActive(false); + } +} diff --git a/UnityFolderScripts/LapComplete.cs.meta b/UnityFolderScripts/LapComplete.cs.meta new file mode 100644 index 0000000..dc0b164 --- /dev/null +++ b/UnityFolderScripts/LapComplete.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 33ae2a7987bb8c748b8edfb3ab5e2c1a +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/UnityFolderScripts/LapTime.cs b/UnityFolderScripts/LapTime.cs new file mode 100644 index 0000000..3af9c97 --- /dev/null +++ b/UnityFolderScripts/LapTime.cs @@ -0,0 +1,49 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; +using UnityEngine.UI; + +public class LapTime : MonoBehaviour +{ + public static int minCount; + public static int secCount; + public static float milliCount; + public static string milliDisplay; + public GameObject min; + public GameObject sec; + public GameObject milli; + + // Update is called once per frame + void Update() + { + milliCount += Time.deltaTime * 10; + milliDisplay = milliCount.ToString("F0"); + milli.GetComponent().text = "" + milliDisplay; //00+milliiDisplay + if (milliCount >= 10) + { + milliCount = 0; + secCount += 1; + } + if (secCount <= 9) + { + sec.GetComponent().text = "0" + secCount + "."; + } + else + { + sec.GetComponent().text = "" + secCount + ".";//For greater than 9 + } + if (secCount >= 60) + { + secCount = 0; + minCount += 1; + } + if (minCount <= 9) + { + min.GetComponent().text = "0" + minCount + ":"; + } + else + { + min.GetComponent().text = "" + minCount + ":"; + } + } +} diff --git a/UnityFolderScripts/LapTime.cs.meta b/UnityFolderScripts/LapTime.cs.meta new file mode 100644 index 0000000..6f53706 --- /dev/null +++ b/UnityFolderScripts/LapTime.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 36f9b4a0866d2ac42840a2b53ac8d3c2 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/UnityFolderScripts/MainCar.cs b/UnityFolderScripts/MainCar.cs new file mode 100644 index 0000000..6d7a4ad --- /dev/null +++ b/UnityFolderScripts/MainCar.cs @@ -0,0 +1,108 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +public class MainCar : MonoBehaviour +{ + public static MainCar instance; + public Rigidbody2D rb; + public float turningForce = 0.4f; + private float turningAmount, speed, direction; + public float forward = 25f, reverse = 15f; + + //smoke trial + public ParticleSystem[] tyreSmoke; + public float maxSmoke = 25f; + private float smokeRate; + public float power; + + //Engine sounds like + public float maxSpeed; + public AudioSource engine; + + //Tyre skid Sound + public AudioSource skidSound; + public float skidFadeSpeed; + + //Skid Trial + public GameObject leftTyre; + public GameObject rightTyre; + public void Awake() + { + instance = this; + } + // Start is called before the first frame update + void Start() + { + rb = GetComponent(); + } + + // Update is called once per frame + void Update() + { + if (Mathf.Abs(power) > .5f) // car accelerate then smoke is max + { + smokeRate = maxSmoke; + } + if (rb.velocity.magnitude <= .5f)//stops the car then smoke is zero + { + smokeRate = 0; + } + for(int i = 0; i < tyreSmoke.Length; i++) + { + var emissionModule = tyreSmoke[i].emission; + emissionModule.rateOverTime = smokeRate; + } + //Engine + if (engine != null) + { + engine.pitch = 1f + ((rb.velocity.magnitude / maxSpeed) * 2f); + } + //Skid + if (skidSound != null) + { + StartSkid(); + if (Mathf.Abs(turningAmount) > 0.99f) + { + skidSound.volume = 1f; + } + else + { + //changing volume + skidSound.volume = Mathf.MoveTowards(skidSound.volume, 0f, skidFadeSpeed * Time.deltaTime); + StopSkid(); + } + } + } + private void FixedUpdate() + { + turningAmount = -Input.GetAxis("Horizontal"); //minus means it will get both left and right + speed = 0f; + if (Input.GetAxis("Accelerator") > 0) + { + speed = Input.GetAxis("Accelerator") * forward; //press accelerator to go forward (move forward) + } + else if (Input.GetAxis("Reverse") < 0) + { + speed = Input.GetAxis("Reverse") * reverse; //press reverse to go reverse (move reverse) + } + //moving the car (next 4 lines) + direction = Mathf.Sign(Vector2.Dot(rb.velocity, rb.GetRelativeVector(Vector2.up))); //return 1 if points to same direction else -1 + rb.rotation += turningAmount * turningForce * rb.velocity.magnitude * direction; + rb.AddRelativeForce(Vector2.up * speed); + rb.AddRelativeForce(-Vector2.right * rb.velocity.magnitude * turningAmount / 2); + } + + + //skid tyre + public void StartSkid() + { + leftTyre.GetComponent().emitting = true; + rightTyre.GetComponent().emitting = true; + } + private void StopSkid() + { + leftTyre.GetComponent().emitting = false; + rightTyre.GetComponent().emitting = false; + } +} diff --git a/UnityFolderScripts/MainCar.cs.meta b/UnityFolderScripts/MainCar.cs.meta new file mode 100644 index 0000000..a66122f --- /dev/null +++ b/UnityFolderScripts/MainCar.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 180232b23958bd5439df519de9c13664 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/UnityFolderScripts/MainMenu.cs b/UnityFolderScripts/MainMenu.cs new file mode 100644 index 0000000..cc41c51 --- /dev/null +++ b/UnityFolderScripts/MainMenu.cs @@ -0,0 +1,44 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; +using UnityEngine.SceneManagement; + +public class MainMenu : MonoBehaviour +{ + public static MainMenu instance; + private string trackToLoad; + public GameObject trackSelect; + + private void Awake() + { + instance = this; + } + // Start is called before the first frame update + void Start() + { + LapTime.minCount = 0;//calling laptime + LapTime.secCount = 0; + LapTime.milliCount = 0; + } + + public void LevelSelect(string trackName) + { + trackToLoad = trackName; + SceneManager.LoadScene(trackToLoad); + } + + public void QuitGame() + { + Application.Quit(); + Debug.Log("quit"); + } + + public void OpenTrackSelect() + { + trackSelect.SetActive(true); + } + public void CloseTrackSelect() + { + trackSelect.SetActive(false); + } +} diff --git a/UnityFolderScripts/MainMenu.cs.meta b/UnityFolderScripts/MainMenu.cs.meta new file mode 100644 index 0000000..790075b --- /dev/null +++ b/UnityFolderScripts/MainMenu.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: f0c4e01aca69dbf48b0e4e1daa38e4fe +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/UnityFolderScripts/MoveOn.cs b/UnityFolderScripts/MoveOn.cs new file mode 100644 index 0000000..6e1031f --- /dev/null +++ b/UnityFolderScripts/MoveOn.cs @@ -0,0 +1,21 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; +using UnityEngine.SceneManagement; + +public class MoveOn : MonoBehaviour +{ + public int moveOnwards; + public string Scene; + // Start is called before the first frame update + void Start() + { + StartCoroutine(SceneChange()); + } + + IEnumerator SceneChange() + { + yield return new WaitForSeconds(moveOnwards); + SceneManager.LoadScene(Scene); + } +} diff --git a/UnityFolderScripts/MoveOn.cs.meta b/UnityFolderScripts/MoveOn.cs.meta new file mode 100644 index 0000000..ecd8c5a --- /dev/null +++ b/UnityFolderScripts/MoveOn.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 89ab6f0b800dda54aaf969368740679c +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/UnityFolderScripts/Player Scripts.meta b/UnityFolderScripts/Player Scripts.meta new file mode 100644 index 0000000..7144bb3 --- /dev/null +++ b/UnityFolderScripts/Player Scripts.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: f18d4e648596f35408bbc3dcad6dff6c +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/UnityFolderScripts/Player Scripts/PlayerVictoryTrigger.cs b/UnityFolderScripts/Player Scripts/PlayerVictoryTrigger.cs new file mode 100644 index 0000000..3c2775f --- /dev/null +++ b/UnityFolderScripts/Player Scripts/PlayerVictoryTrigger.cs @@ -0,0 +1,28 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; +using UnityEngine.SceneManagement; +public class PlayerVictoryTrigger : MonoBehaviour +{ + public int currentLap; + public int maxLap; + + // Start is called before the first frame update + void Start() + { + currentLap = maxLap; + } + private void OnTriggerEnter2D(Collider2D other) + { + if (other.tag == "Player") + { + currentLap--; + if (currentLap <= 0) + { + SceneManager.LoadScene("Victory"); + } + } + } + + +} diff --git a/UnityFolderScripts/Player Scripts/PlayerVictoryTrigger.cs.meta b/UnityFolderScripts/Player Scripts/PlayerVictoryTrigger.cs.meta new file mode 100644 index 0000000..dc7be99 --- /dev/null +++ b/UnityFolderScripts/Player Scripts/PlayerVictoryTrigger.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: e0a44b16b6e9faa43a7cb9c6c1cecb6e +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/UnityFolderScripts/Speedometer.cs b/UnityFolderScripts/Speedometer.cs new file mode 100644 index 0000000..6a2151d --- /dev/null +++ b/UnityFolderScripts/Speedometer.cs @@ -0,0 +1,27 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; +using UnityEngine.UI; +public class Speedometer : MonoBehaviour +{ + public Rigidbody2D target; + public float maxSpeed; + public float minSpeed,maxSpeedAngle; + public Text speedLabel; + public RectTransform arrow; + private float speed; + + // Update is called once per frame + void Update() + { + speed = target.velocity.magnitude * 3.6f; + if (speedLabel != null) + { + speedLabel.text = ((int)speed) + "KM/H"; + } + if (arrow != null) + { + arrow.localEulerAngles = new Vector3(0, 0, Mathf.Lerp(minSpeed, maxSpeedAngle, speed / maxSpeed));//Lerp is for smooth movement + } + } +} diff --git a/UnityFolderScripts/Speedometer.cs.meta b/UnityFolderScripts/Speedometer.cs.meta new file mode 100644 index 0000000..960e560 --- /dev/null +++ b/UnityFolderScripts/Speedometer.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 58062aea590a3db4ab284c74350716bc +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/UnityFolderScripts/WheelController.cs b/UnityFolderScripts/WheelController.cs new file mode 100644 index 0000000..7830250 --- /dev/null +++ b/UnityFolderScripts/WheelController.cs @@ -0,0 +1,23 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +public class WheelController : MonoBehaviour +{ + private Vector3 angle; + public float wheelAngle, maxwheelAngle = 30f; + + // Update is called once per frame + void Update() + { + wheelAngle = -Input.GetAxis("Horizontal") * maxwheelAngle; //- means left + } + + private void LateUpdate() + { + // Makes wheel turn left or right (next 3 lines) + angle = transform.localEulerAngles; //freedimensional rotation in individual axis + angle.z = wheelAngle; + transform.localEulerAngles = angle; + } +} diff --git a/UnityFolderScripts/WheelController.cs.meta b/UnityFolderScripts/WheelController.cs.meta new file mode 100644 index 0000000..e46551b --- /dev/null +++ b/UnityFolderScripts/WheelController.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 6e460cbb3a4358a4dbf75a0ed2d549ce +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/UnityFolder/readme.md b/UnityFolderScripts/readme.md similarity index 100% rename from UnityFolder/readme.md rename to UnityFolderScripts/readme.md