Survival Shooter

The goal of this game is to survive as long as possible against endless waves of stuffed zombie animals.
I added a power pickup that is rotating to get the players attention.
If you pick it up you will instantly run faster, and as a bonus you will run even faster when your health reaches 20%.
You will also score points if you kill the enemies. 10 points for the zombunny and zombear who you have to hit 5 times in order to kill it, and 50 points for the hellevant who you have to shoot 15 times in order to kill it.

My extra assignment was to make a power up what is the one I described before.
I first thought about a power up that would let you shoot faster but then I thought about one more defensively so you can run away from danger even faster.

SurvivalShooter Unity

SurvivalShooter ingame

bonusPickup.cs

using UnityEngine; using System.Collections; public class bonusPickup : MonoBehaviour { public float speedBonus; void Start() { speedBonus = 4f; } void Update() { } } //////////// using UnityEngine; using System.Collections; public class Ratator : MonoBehaviour { void Update () { transform.Rotate(new Vector3(0, 30, 0) * Time.deltaTime); } } //////////// using UnityEngine; using System.Collections; public class CameraFollow : MonoBehaviour { public Transform target; public float smoothing = 5f; Vector3 offset; void Start() { offset = transform.position - target.position; } void FixedUpdate() { Vector3 targetCamPos = target.position + offset; transform.position = Vector3.Lerp(transform.position, targetCamPos, smoothing * Time.deltaTime); } } ///////////// using UnityEngine; using System.Collections; public class EnemyAttack : MonoBehaviour { public float timeBetweenAttacks = 0.5f; public int attackDamage = 10; private static int health; Animator anim; GameObject player; PlayerHealth playerHealth; EnemyHealth enemyHealth; bool playerInRange; float timer; void Awake () { player = GameObject.FindGameObjectWithTag ("Player"); playerHealth = player.GetComponent (); enemyHealth = GetComponent(); anim = GetComponent (); } void OnTriggerEnter (Collider other) { if(other.gameObject == player) { playerInRange = true; } } void OnTriggerExit (Collider other) { if(other.gameObject == player) { playerInRange = false; } } void Update () { health = PlayerHealth.currentHealth; timer += Time.deltaTime; if(timer >= timeBetweenAttacks && playerInRange && enemyHealth.currentHealth > 0) { Attack (); } if(health <= 0) { anim.SetTrigger ("PlayerDead"); } } void Attack () { timer = 0f; if(health > 0) { playerHealth.TakeDamage (attackDamage); } } } /////////////// using UnityEngine; public class EnemyHealth : MonoBehaviour { public int startingHealth = 100; public int currentHealth; public float sinkSpeed = 2.5f; public int scoreValue = 10; public AudioClip deathClip; Animator anim; AudioSource enemyAudio; ParticleSystem hitParticles; CapsuleCollider capsuleCollider; bool isDead; bool isSinking; void Awake () { anim = GetComponent (); enemyAudio = GetComponent (); hitParticles = GetComponentInChildren (); capsuleCollider = GetComponent (); currentHealth = startingHealth; } void Update () { if(isSinking) { transform.Translate (-Vector3.up * sinkSpeed * Time.deltaTime); } } public void TakeDamage (int amount, Vector3 hitPoint) { if(isDead) return; enemyAudio.Play (); currentHealth -= amount; hitParticles.transform.position = hitPoint; hitParticles.Play(); if(currentHealth <= 0) { Death (); } } void Death () { isDead = true; capsuleCollider.isTrigger = true; anim.SetTrigger ("Dead"); enemyAudio.clip = deathClip; enemyAudio.Play (); } public void StartSinking () { GetComponent ().enabled = false; GetComponent ().isKinematic = true; isSinking = true; ScoreManager.score += scoreValue; Destroy (gameObject, 2f); } } ///////////// using UnityEngine; using System.Collections; public class EnemyMovement : MonoBehaviour { Transform player; PlayerHealth playerHealth; EnemyHealth enemyHealth; NavMeshAgent nav; private static int health; void Awake () { player = GameObject.FindGameObjectWithTag ("Player").transform; playerHealth = player.GetComponent (); enemyHealth = GetComponent (); nav = GetComponent (); } void Update () { health = PlayerHealth.currentHealth; if (enemyHealth.currentHealth > 0 && health > 0) { nav.SetDestination (player.position); } else { nav.enabled = false; } } } ////////////// using UnityEngine; public class EnemyManager : MonoBehaviour { public PlayerHealth playerHealth; public GameObject enemy; public float spawnTime = 3f; public Transform[] spawnPoints; private static int health; void Start () { InvokeRepeating ("Spawn", spawnTime, spawnTime); health = PlayerHealth.currentHealth; } void Spawn () { if(health <= 0f) { return; } int spawnPointIndex = Random.Range (0, spawnPoints.Length); Instantiate (enemy, spawnPoints[spawnPointIndex].position, spawnPoints[spawnPointIndex].rotation); } } ////////////// using UnityEngine; public class GameOverManager : MonoBehaviour { public PlayerHealth playerHealth; public float restartDelay = 5f; private static int health; Animator anim; float restartTimer; void Awake() { anim = GetComponent(); } void Update() { health = PlayerHealth.currentHealth; if (health <= 0) { anim.SetTrigger("GameOver"); restartTimer += Time.deltaTime; if (restartTimer >= restartDelay) { Application.LoadLevel(Application.loadedLevel); } } } } ////////////// using UnityEngine; using UnityEngine.UI; using System.Collections; public class ScoreManager : MonoBehaviour { public static int score; Text text; void Awake () { text = GetComponent (); score = 0; } void Update () { text.text = "Score: " + score; } } ////////////// using UnityEngine; using UnityEngine.UI; using System.Collections; using UnityEngine.SceneManagement; public class PlayerHealth : MonoBehaviour { public int startingHealth = 100; public static int currentHealth; public Slider healthSlider; public Image damageImage; public AudioClip deathClip; public float flashSpeed = 5f; public Color flashColour = new Color(1f, 0f, 0f, 0.1f); Animator anim; AudioSource playerAudio; PlayerMovement playerMovement; PlayerShooting playerShooting; bool isDead; bool damaged; void Awake () { anim = GetComponent (); playerAudio = GetComponent (); playerMovement = GetComponent (); playerShooting = GetComponentInChildren (); currentHealth = startingHealth; } void Update () { if(damaged) { damageImage.color = flashColour; } else { damageImage.color = Color.Lerp (damageImage.color, Color.clear, flashSpeed * Time.deltaTime); } damaged = false; } public void TakeDamage (int amount) { damaged = true; currentHealth -= amount; healthSlider.value = currentHealth; playerAudio.Play (); if(currentHealth <= 0 && !isDead) { Death (); } } void Death () { isDead = true; playerShooting.DisableEffects (); anim.SetTrigger ("Die"); playerAudio.clip = deathClip; playerAudio.Play (); playerMovement.enabled = false; playerShooting.enabled = false; } public void RestartLevel () { SceneManager.LoadScene (0); } } //////////////// using UnityEngine; public class PlayerMovement : MonoBehaviour { public float speed = 6f; private PlayerShooting playerShooting; private static int health; bool powerUp; Vector3 movement; Animator anim; Rigidbody playerRigidbody; int floorMask; float camRayLength = 100f; int playerHealth; void Awake() { floorMask = LayerMask.GetMask("Floor"); anim = GetComponent(); playerRigidbody = GetComponent(); powerUp = false; } void Update() { health = PlayerHealth.currentHealth; if (powerUp == true) { speed = 8.0f; if (health <= 20) { speed = 10.0f; } } } void FixedUpdate() { float h = Input.GetAxisRaw("Horizontal"); float v = Input.GetAxisRaw("Vertical"); Move(h, v); Turning(); Animating(h, v); } void Move(float h, float v) { movement.Set(h, 0f, v); movement = movement.normalized * speed * Time.deltaTime; playerRigidbody.MovePosition(transform.position + movement); } void Turning() { Ray camRay = Camera.main.ScreenPointToRay(Input.mousePosition); RaycastHit floorHit; if (Physics.Raycast(camRay, out floorHit, camRayLength, floorMask)) { Vector3 playerToMouse = floorHit.point - transform.position; playerToMouse.y = 0f; Quaternion newRotation = Quaternion.LookRotation(playerToMouse); playerRigidbody.MoveRotation(newRotation); } } void Animating(float h, float v) { bool walking = h != 0f || v != 0f; anim.SetBool("IsWalking", walking); } void OnTriggerEnter(Collider other) { if (other.gameObject.tag == ("PickUp")) { // bonusPickup tempPowerup; // tempPowerup = other.gameObject.GetComponent(); // PlayerShooting TempPowerup; // TempPowerup = other.gameObject.GetComponent(); // tempPowerup.speedBonus = TempPowerup.damagePerShot; // speed += tempPowerup.speedBonus; Destroy(other.gameObject); powerUp = true; } } } /////////////// using UnityEngine; public class PlayerShooting : MonoBehaviour { public int damagePerShot = 20; public float timeBetweenBullets = 0.15f; public float range = 100f; float timer; Ray shootRay; RaycastHit shootHit; int shootableMask; ParticleSystem gunParticles; LineRenderer gunLine; AudioSource gunAudio; Light gunLight; float effectsDisplayTime = 0.2f; void Awake() { shootableMask = LayerMask.GetMask("Shootable"); gunParticles = GetComponent(); gunLine = GetComponent(); gunAudio = GetComponent(); gunLight = GetComponent(); } void Update() { timer += Time.deltaTime; //if (pickUp == 1) //{ // timeBetweenBullets = 0.07f; // print("succes"); //} //timeBetweenBullets = pickup // if (Input.GetButton("Fire1") && timer >= timeBetweenBullets && Time.timeScale != 0) { Shoot(); } if (timer >= timeBetweenBullets * effectsDisplayTime) { DisableEffects(); } } public void DisableEffects() { gunLine.enabled = false; gunLight.enabled = false; } void Shoot() { timer = 0f; gunAudio.Play(); gunLight.enabled = true; gunParticles.Stop(); gunParticles.Play(); gunLine.enabled = true; gunLine.SetPosition(0, transform.position); shootRay.origin = transform.position; shootRay.direction = transform.forward; if (Physics.Raycast(shootRay, out shootHit, range, shootableMask)) { EnemyHealth enemyHealth = shootHit.collider.GetComponent(); if (enemyHealth != null) { enemyHealth.TakeDamage(damagePerShot, shootHit.point); } gunLine.SetPosition(1, shootHit.point); } else { gunLine.SetPosition(1, shootRay.origin + shootRay.direction * range); } } } ////////////////