diff options
| author | Tom Harley | 2018-09-03 23:34:21 +0100 |
|---|---|---|
| committer | Tom Harley | 2018-09-03 23:36:01 +0100 |
| commit | 5440734d820606b29a795c46172ade5d7eba8efb (patch) | |
| tree | 85867f40afb02cfa2a5028b515ed0a195866b7e9 /Assets/Scripts | |
| download | powerless-5440734d820606b29a795c46172ade5d7eba8efb.tar.gz powerless-5440734d820606b29a795c46172ade5d7eba8efb.zip | |
Initial commit
Diffstat (limited to 'Assets/Scripts')
| -rw-r--r-- | Assets/Scripts/Brain.cs | 57 | ||||
| -rw-r--r-- | Assets/Scripts/Brain.cs.meta | 11 | ||||
| -rw-r--r-- | Assets/Scripts/Bullet.cs | 100 | ||||
| -rw-r--r-- | Assets/Scripts/Bullet.cs.meta | 11 | ||||
| -rw-r--r-- | Assets/Scripts/CharacterControl.cs | 239 | ||||
| -rw-r--r-- | Assets/Scripts/CharacterControl.cs.meta | 11 | ||||
| -rw-r--r-- | Assets/Scripts/Crawler.cs | 51 | ||||
| -rw-r--r-- | Assets/Scripts/Crawler.cs.meta | 11 | ||||
| -rw-r--r-- | Assets/Scripts/DoorLogic.cs | 116 | ||||
| -rw-r--r-- | Assets/Scripts/DoorLogic.cs.meta | 11 | ||||
| -rw-r--r-- | Assets/Scripts/Enemy.cs | 28 | ||||
| -rw-r--r-- | Assets/Scripts/Enemy.cs.meta | 11 | ||||
| -rw-r--r-- | Assets/Scripts/Flyer.cs | 40 | ||||
| -rw-r--r-- | Assets/Scripts/Flyer.cs.meta | 11 | ||||
| -rw-r--r-- | Assets/Scripts/FollowPlayer.cs | 12 | ||||
| -rw-r--r-- | Assets/Scripts/FollowPlayer.cs.meta | 11 | ||||
| -rw-r--r-- | Assets/Scripts/ICanDie.cs | 31 | ||||
| -rw-r--r-- | Assets/Scripts/ICanDie.cs.meta | 11 | ||||
| -rw-r--r-- | Assets/Scripts/Upgrade.cs | 50 | ||||
| -rw-r--r-- | Assets/Scripts/Upgrade.cs.meta | 11 |
20 files changed, 834 insertions, 0 deletions
diff --git a/Assets/Scripts/Brain.cs b/Assets/Scripts/Brain.cs new file mode 100644 index 0000000..36c2493 --- /dev/null +++ b/Assets/Scripts/Brain.cs @@ -0,0 +1,57 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +public class Brain : MonoBehaviour { + public float chargeInterval = 2f; + public float chargeDuration = 1f; + + public GameObject wavePrefab; + public Vector2 waveSpawnOffset = new Vector2(0, 0); + public Vector2 waveVelocity = new Vector2(1, 0); + + private bool charging = false; + private bool facingRight; + + private Animator anim; + + public bool Charging { + get { + return charging; + } + + set { + charging = value; + if (anim) anim.SetBool("charging", value); + } + } + + void Start() { + anim = GetComponent<Animator>(); + + facingRight = !GetComponent<SpriteRenderer>().flipX; + } + + void Awake() { + Idle(); + } + + void Idle() { + Charging = false; + Invoke("Charge", chargeInterval); + } + + void Charge() { + Charging = true; + Invoke("Fire", chargeDuration); + } + + void Fire() { + Vector2 spawnPosition = this.transform.position + (Vector3)((facingRight ? 1 : -1) * waveSpawnOffset); + GameObject wave = Instantiate(wavePrefab, spawnPosition, Quaternion.identity); + Rigidbody2D wrb = wave.GetComponent<Rigidbody2D>(); + wrb.velocity = waveVelocity * (facingRight ? 1 : -1); + + Idle(); + } +} diff --git a/Assets/Scripts/Brain.cs.meta b/Assets/Scripts/Brain.cs.meta new file mode 100644 index 0000000..7b926ff --- /dev/null +++ b/Assets/Scripts/Brain.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 584b9ebafab614fcc9d4ac04a35c35ab +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/Bullet.cs b/Assets/Scripts/Bullet.cs new file mode 100644 index 0000000..5e8b1fc --- /dev/null +++ b/Assets/Scripts/Bullet.cs @@ -0,0 +1,100 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +public class Bullet : MonoBehaviour { + public string colour = "yellow"; + public float damage = 1f; + + public AudioClip bounceNoise; + public float bounceNoiseVolume = 1.0f; + public AudioClip hitWallNoise; + public float hitWallNoiseVolume = 1.0f; + public AudioClip hitEnemyNoise; + public float hitEnemyNoiseVolume = 1.0f; + public AudioClip genericHitNoise; + public float genericHitNoiseVolume = 1.0f; + + public bool bounceOnWrongDoors = true; + + private bool leftPlayer = false; + + private Rigidbody2D body; + private AudioSource audio; + + void Start() { + body = GetComponent<Rigidbody2D>(); + audio = GetComponent<AudioSource>(); + } + + void Update() { + if (body.velocity.x < 0) { + transform.localScale = new Vector2(-1, 1); + } else if (body.velocity.x > 0) { + transform.localScale = new Vector2(1, 1); + } else { + transform.rotation = Quaternion.Euler(new Vector3(0, 0, 90)); + } + } + + void OnTriggerEnter2D(Collider2D collider) { + if (!leftPlayer) { + leftPlayer = true; + return; + } + + if (genericHitNoise) audio.PlayOneShot(genericHitNoise, genericHitNoiseVolume); + + GameObject other = collider.gameObject; + + switch (other.tag) { + case "Door": + DoorLogic dl = other.GetComponent<DoorLogic>(); + if (dl.colour == this.colour) { + dl.Open(); + Die(); + } else { + if (bounceOnWrongDoors) { this.Bounce(); } else { Die(); } + } + break; + + case "Player": + CharacterControl cc = other.GetComponent<CharacterControl>(); + cc.Damaged(); + Die(); + break; + + case "Enemy": + if (hitEnemyNoise) audio.PlayOneShot(hitEnemyNoise, hitEnemyNoiseVolume); + ICanDie icd = other.GetComponent<ICanDie>(); + if (icd) icd.Hit(damage); + Die(); + break; + + case "Projectile": + // do nothing + break; + + default: + if (hitWallNoise) audio.PlayOneShot(hitWallNoise, hitWallNoiseVolume); + Die(); + break; + } + } + + void Die() { + GetComponent<SpriteRenderer>().enabled = false; + GetComponent<BoxCollider2D>().enabled = false; + + Invoke("ReallyDie", 3f); + } + + void ReallyDie() { + Destroy(this.gameObject); + } + + void Bounce() { + if (bounceNoise) audio.PlayOneShot(bounceNoise, bounceNoiseVolume); + body.velocity = new Vector2(body.velocity.x * -1, body.velocity.y); + } +} diff --git a/Assets/Scripts/Bullet.cs.meta b/Assets/Scripts/Bullet.cs.meta new file mode 100644 index 0000000..f60c12d --- /dev/null +++ b/Assets/Scripts/Bullet.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 4c4f332df3f094e08b0c5e8bf7685b67 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/CharacterControl.cs b/Assets/Scripts/CharacterControl.cs new file mode 100644 index 0000000..cb447bf --- /dev/null +++ b/Assets/Scripts/CharacterControl.cs @@ -0,0 +1,239 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +public class CharacterControl : MonoBehaviour { + public float moveForce = 365f; + public AudioClip walkNoise; + public float walkNoiseVolume = 1f; + public float walkNoiseFrequency = 1f; + + public float jumpForce = 1000f; + public float jumpSustainForce = 0f; + public AudioClip jumpNoise; + public float jumpNoiseVolume = 1f; + public AudioClip landNoise; + public float landNoiseVolume = 1f; + + public bool limitHorizontalSpeed = true; + public float maxHorizontalSpeed = 5f; + public bool limitHorizontalSpeedWhenDamaged = false; + + public bool limitVerticalSpeed = true; + public float maxVerticalSpeed = 5f; + public bool limitVerticalSpeedWhenDamaged = false; + public bool limitJumpSpeed = false; + + public float damageDuration = 1f; + public Vector2 knockbackForce = new Vector2(-400f, 200f); + public AudioClip damageNoise; + public float damageNoiseVolume = 1f; + + public GameObject bulletPrefab; + public AudioClip shootNoise; + public float shootNoiseVolume = 1f; + public float bulletSpawnHeightOffset = 0f; + public float bulletSpeed = 1f; + public float shootCooldown; + + private bool grounded; + private bool damaged; + private bool facingRight; + private bool shotRecently; + + private Rigidbody2D body; + private BoxCollider2D coll; + private Animator anim; + private Transform trans; + private AudioSource audio; + + private float distToGround; + + void Start() { + body = GetComponent<Rigidbody2D>(); + coll = GetComponent<BoxCollider2D>(); + anim = GetComponent<Animator>(); + trans = GetComponent<Transform>(); + audio = GetComponent<AudioSource>(); + + distToGround = coll.bounds.extents.y; + } + + void Awake() { + Invoke("WalkNoisily", 0.1f); + } + + void WalkNoisily() { + if (grounded && !damaged && (Input.GetButton("Move Left") || Input.GetButton("Move Right"))) { + if (walkNoise) audio.PlayOneShot(walkNoise, walkNoiseVolume); + } + + Invoke("WalkNoisily", walkNoiseFrequency); + } + + void Update() { + if (!damaged) { + if (Input.GetButtonDown("Damage")) { + Damaged(); + } + } + + grounded = IsGrounded(); + anim.SetBool("grounded", grounded); + if (grounded && body.velocity.y < 0) Undamaged(); + + if (!damaged) { + if (grounded && Input.GetButtonDown("Jump")) { + Jump(); + } + + if (!shotRecently && Input.GetButtonDown("Shoot")) { + Shoot(); + } + + anim.SetBool("looking_up", Input.GetButton("Look Up")); + } + } + + void FixedUpdate() { + if (!damaged) { + Walk(); + } + + LimitHorizontalSpeed(); + LimitVerticalSpeed(); + + if (!damaged && !grounded && Input.GetButton("Jump") && body.velocity.y > 0) { + JumpHigher(); + } + + FaceMovement(); + } + + void Shoot() { + shotRecently = true; + anim.SetBool("just_shot", true); + + if (shootNoise) audio.PlayOneShot(shootNoise, shootNoiseVolume); + + Vector3 spawnPosition = trans.position + new Vector3(0, bulletSpawnHeightOffset); + + GameObject bullet = Instantiate(bulletPrefab, spawnPosition, Quaternion.identity); + Rigidbody2D rb = bullet.GetComponent<Rigidbody2D>(); + + if (Input.GetButton("Look Up")) { + rb.velocity = Vector3.up * bulletSpeed; + } else if (facingRight) { + rb.velocity = Vector3.right * bulletSpeed; + } else { + rb.velocity = Vector3.left * bulletSpeed; + } + + Invoke("Unshoot", shootCooldown); + } + + void Unshoot() { + shotRecently = false; + anim.SetBool("just_shot", false); + } + + public void Damaged() { + if (damaged) return; + + if (damageNoise) audio.PlayOneShot(damageNoise, damageNoiseVolume); + + // reset momentum + body.velocity = Vector2.zero; + + body.AddForce(new Vector2(trans.localScale.x * knockbackForce.x, knockbackForce.y)); + + damaged = true; + anim.SetBool("hurt", true); + + Invoke("Undamaged", damageDuration); + } + + void Undamaged() { + damaged = false; + anim.SetBool("hurt", false); + } + + bool IsGrounded() { + float xSize = coll.bounds.extents.x; + + Debug.DrawRay( + transform.position + Vector3.left * xSize + Vector3.down * distToGround, + Vector2.down * 0.1f, Color.red); + Debug.DrawRay( + transform.position + Vector3.right * xSize + Vector3.down * distToGround, + Vector2.down * 0.1f, Color.red); + + bool ret = Physics2D.Raycast( + transform.position + Vector3.left * xSize + Vector3.down * (distToGround - 0.1f), + Vector2.down, 0.2f) + || Physics2D.Raycast( + transform.position + Vector3.right * xSize + Vector3.down * (distToGround - 0.1f), + Vector2.down, 0.2f); + + if (ret && !grounded) { + if (landNoise) audio.PlayOneShot(landNoise, landNoiseVolume); + } + + return ret; + } + + void Jump() { + if (jumpNoise) audio.PlayOneShot(jumpNoise, jumpNoiseVolume); + + body.AddForce(Vector2.up * jumpForce); + } + + void JumpHigher() { + body.AddForce(Vector2.up * jumpSustainForce); + } + + void Walk() { + if (Input.GetButton("Move Right")) { + anim.SetBool("walking", true); + facingRight = true; + body.AddForce(Vector2.right * moveForce); + } + + if (Input.GetButton("Move Left")) { + anim.SetBool("walking", true); + facingRight = false; + body.AddForce(Vector2.left * moveForce); + } + + if (!Input.GetButton("Move Right") && !Input.GetButton("Move Left")) { + anim.SetBool("walking", false); + body.velocity = new Vector2(0, body.velocity.y); + } + } + + void LimitHorizontalSpeed() { + if (limitHorizontalSpeed && (!damaged || limitHorizontalSpeedWhenDamaged)) { + if (body.velocity.x > maxHorizontalSpeed) { + body.velocity = new Vector2(maxHorizontalSpeed, body.velocity.y); + } else if (body.velocity.x < -maxHorizontalSpeed) { + body.velocity = new Vector2(-maxHorizontalSpeed, body.velocity.y); + } + } + } + + void LimitVerticalSpeed() { + if (limitVerticalSpeed && (!damaged || limitVerticalSpeedWhenDamaged)) { + if (limitJumpSpeed && body.velocity.y > maxVerticalSpeed) { + body.velocity = new Vector2(body.velocity.x, maxVerticalSpeed); + } else if (body.velocity.y < -maxVerticalSpeed) { + body.velocity = new Vector2(body.velocity.x, -maxVerticalSpeed); + } + } + } + + void FaceMovement() { + float scale = Mathf.Abs(trans.localScale.x); + + trans.localScale = new Vector2((facingRight ? 1 : -1) * scale, scale); + } +} diff --git a/Assets/Scripts/CharacterControl.cs.meta b/Assets/Scripts/CharacterControl.cs.meta new file mode 100644 index 0000000..ebe576e --- /dev/null +++ b/Assets/Scripts/CharacterControl.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 8491635091e7f477ca8c15e144d09278 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/Crawler.cs b/Assets/Scripts/Crawler.cs new file mode 100644 index 0000000..3b13f24 --- /dev/null +++ b/Assets/Scripts/Crawler.cs @@ -0,0 +1,51 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +public class Crawler : MonoBehaviour { + public Vector2 velocity = new Vector2(1, 0); + + public float raycastLength = 0.1f; + + private BoxCollider2D coll; + private Rigidbody2D body; + + void Start() { + coll = GetComponent<BoxCollider2D>(); + body = GetComponent<Rigidbody2D>(); + + body.velocity = velocity; + } + + void FixedUpdate() { + Vector2 bounds = coll.bounds.extents; + + RaycastHit2D leftHit = Physics2D.Raycast( + transform.position + Vector3.left * bounds.x + Vector3.down * bounds.y, + Vector2.down, raycastLength); + + RaycastHit2D rightHit = Physics2D.Raycast( + transform.position + Vector3.right * bounds.x + Vector3.down * bounds.y, + Vector2.down, raycastLength); + + Debug.DrawRay( + transform.position + Vector3.left * bounds.x + Vector3.down * bounds.y, + Vector2.down, Color.blue); + + Debug.DrawRay( + transform.position + Vector3.right * bounds.x + Vector3.down * bounds.y, + Vector2.down, Color.red); + + if (!leftHit || !rightHit) { + Flip(); + } + } + + void Flip() { + body.velocity = -body.velocity; + } + + void Update() { + transform.localScale = new Vector2(Mathf.Sign(body.velocity.x), 1); + } +} diff --git a/Assets/Scripts/Crawler.cs.meta b/Assets/Scripts/Crawler.cs.meta new file mode 100644 index 0000000..e8b4983 --- /dev/null +++ b/Assets/Scripts/Crawler.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: cec586ee851db41fb881d6ca71a44c6f +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/DoorLogic.cs b/Assets/Scripts/DoorLogic.cs new file mode 100644 index 0000000..5222bd1 --- /dev/null +++ b/Assets/Scripts/DoorLogic.cs @@ -0,0 +1,116 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +public class DoorLogic : MonoBehaviour { + public string colour = "yellow"; + public bool open = false; + + public GameObject player; + public GameObject exit; + + public AudioClip openNoise; + public float openNoiseVolume = 1f; + + public float playerProximity = 0.6f; + public float playerPlacedOffset = 2f; + + private Animator anim; + private BoxCollider2D coll; + private AudioSource audio; + + void OnDrawGizmos() { + if (exit != null) { + Gizmos.color = Color.white; + Gizmos.DrawLine(transform.position, exit.transform.position); + } + } + + void Start() { + anim = GetComponent<Animator>(); + coll = GetComponent<BoxCollider2D>(); + audio = GetComponent<AudioSource>(); + + if (exit) { + DoorLogic dl = exit.GetComponent<DoorLogic>(); + dl.exit = this.gameObject; + } + + if (!player) { + player = GameObject.FindGameObjectsWithTag("Player")[0]; + } + + SetAnimationColour(); + OpenOrClosed(open); + } + + public void Open() { + if (openNoise) audio.PlayOneShot(openNoise, openNoiseVolume); + + OpenOrClosed(true); + } + + void Close() { + OpenOrClosed(false); + } + + void OpenOrClosed(bool which) { + open = which; + anim.SetBool("open", which); + coll.isTrigger = which; + } + + void SetAnimationColour() { + switch (colour) { + case "yellow": + anim.SetInteger("colour", 0); + break; + case "blue": + anim.SetInteger("colour", 1); + break; + case "green": + anim.SetInteger("colour", 2); + break; + case "red": + anim.SetInteger("colour", 3); + break; + } + } + + void FixedUpdate() { + if (exit) { + if (Vector2.Distance(player.transform.position, this.transform.position) + < playerProximity) { + Teleport(player, exit); + } + } + } + + void Teleport(GameObject player, GameObject exit) { + float yDiff = this.transform.position.y - player.transform.position.y; + + player.transform.position = exit.transform.position + + (Vector3.right * (exit.GetComponent<SpriteRenderer>().flipX ? -1 : 1) * + playerPlacedOffset) - Vector3.up * yDiff; + + ResetAll(); + } + + public void Reset() { + Close(); + } + + void ResetAll() { + GameObject[] enemies = GameObject.FindGameObjectsWithTag("Enemy"); + foreach (GameObject enemy in enemies) { + Enemy script = enemy.GetComponent<Enemy>(); + script.Reset(); + } + + GameObject[] doors = GameObject.FindGameObjectsWithTag("Door"); + foreach (GameObject door in doors) { + DoorLogic script = door.GetComponent<DoorLogic>(); + script.Reset(); + } + } +} diff --git a/Assets/Scripts/DoorLogic.cs.meta b/Assets/Scripts/DoorLogic.cs.meta new file mode 100644 index 0000000..403d663 --- /dev/null +++ b/Assets/Scripts/DoorLogic.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 41555b078fec34407880f5efe0bf6e23 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/Enemy.cs b/Assets/Scripts/Enemy.cs new file mode 100644 index 0000000..a7af21f --- /dev/null +++ b/Assets/Scripts/Enemy.cs @@ -0,0 +1,28 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +public class Enemy : MonoBehaviour { + private Vector2 start; + + void OnTriggerStay2D(Collider2D other) { + GameObject ogo = other.gameObject; + switch (ogo.tag) { + case "Player": + CharacterControl script = ogo.GetComponent<CharacterControl>(); + script.Damaged(); + break; + } + } + + void Start() { + start = this.transform.position; + } + + public void Reset() { + Debug.Log(this); + this.transform.position = start; + GetComponent<SpriteRenderer>().enabled = true; + GetComponent<BoxCollider2D>().enabled = true; + } +} diff --git a/Assets/Scripts/Enemy.cs.meta b/Assets/Scripts/Enemy.cs.meta new file mode 100644 index 0000000..b4a592d --- /dev/null +++ b/Assets/Scripts/Enemy.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 85ec52a24e07a48618d5a22119b938fc +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/Flyer.cs b/Assets/Scripts/Flyer.cs new file mode 100644 index 0000000..dfb5f2e --- /dev/null +++ b/Assets/Scripts/Flyer.cs @@ -0,0 +1,40 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +public class Flyer : MonoBehaviour { + public Vector2 velocity = new Vector2(1, 0); + + private Rigidbody2D body; + + void Start() { + body = GetComponent<Rigidbody2D>(); + body.velocity = velocity; + } + + void OnTriggerEnter2D(Collider2D other) { + switch (other.gameObject.tag) { + case "Platform": + Flip(); + break; + } + } + + void OnTriggerStay2D(Collider2D other) { + GameObject ogo = other.gameObject; + switch (ogo.tag) { + case "Player": + CharacterControl cc = GetComponent<CharacterControl>(); + if (cc) cc.Damaged(); + break; + } + } + + void Flip() { + body.velocity = -body.velocity; + } + + void Update() { + transform.localScale = new Vector2(Mathf.Sign(body.velocity.x), 1); + } +} diff --git a/Assets/Scripts/Flyer.cs.meta b/Assets/Scripts/Flyer.cs.meta new file mode 100644 index 0000000..565e145 --- /dev/null +++ b/Assets/Scripts/Flyer.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 4afcd182cbead42baac069350c0ab735 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/FollowPlayer.cs b/Assets/Scripts/FollowPlayer.cs new file mode 100644 index 0000000..096fd4d --- /dev/null +++ b/Assets/Scripts/FollowPlayer.cs @@ -0,0 +1,12 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +public class FollowPlayer : MonoBehaviour { + public GameObject player; + public Vector3 offset = new Vector3(0, 0, -10); + + void LateUpdate() { + transform.position = player.transform.position + offset; + } +} diff --git a/Assets/Scripts/FollowPlayer.cs.meta b/Assets/Scripts/FollowPlayer.cs.meta new file mode 100644 index 0000000..f32834d --- /dev/null +++ b/Assets/Scripts/FollowPlayer.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: e1f760dfc896649dc9da8a877ec445c3 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/ICanDie.cs b/Assets/Scripts/ICanDie.cs new file mode 100644 index 0000000..d6ff6d1 --- /dev/null +++ b/Assets/Scripts/ICanDie.cs @@ -0,0 +1,31 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +public class ICanDie : MonoBehaviour { + public float health = 3; + + public AudioClip deathNoise; + public float deathNoiseVolume = 1f; + + private AudioSource audio; + + void Start() { + audio = GetComponent<AudioSource>(); + } + + public void Hit(float damage) { + health -= damage; + + if (health <= 0) { + Die(); + } + } + + public void Die() { + if (deathNoise) audio.PlayOneShot(deathNoise, deathNoiseVolume); + + GetComponent<SpriteRenderer>().enabled = false; + GetComponent<BoxCollider2D>().enabled = false; + } +} diff --git a/Assets/Scripts/ICanDie.cs.meta b/Assets/Scripts/ICanDie.cs.meta new file mode 100644 index 0000000..4e8aec6 --- /dev/null +++ b/Assets/Scripts/ICanDie.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: a5981c8b0bf394cba826075e857ab60d +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/Upgrade.cs b/Assets/Scripts/Upgrade.cs new file mode 100644 index 0000000..88d8e52 --- /dev/null +++ b/Assets/Scripts/Upgrade.cs @@ -0,0 +1,50 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +public class Upgrade : MonoBehaviour { + public AudioClip obtainNoise; + public float obtainNoiseVolume = 1f; + + public float messageDisplayTime = 3f; + + private Animator anim; + private AudioSource audio; + + void Start() { + anim = GetComponent<Animator>(); + audio = GetComponent<AudioSource>(); + } + + void OnTriggerEnter2D(Collider2D other) { + switch (other.gameObject.tag) { + case "Projectile": + Break(); + break; + } + } + + void Break() { + anim.SetBool("broken", true); + + if (obtainNoise) audio.PlayOneShot(obtainNoise, obtainNoiseVolume); + GetComponent<BoxCollider2D>().enabled = false; + + Time.timeScale = 0; + + GameObject.FindGameObjectsWithTag("Message")[0].GetComponent<SpriteRenderer>().enabled = true; + } + + void Update() { + Debug.Log("woa"); + if (Input.GetButtonDown("Shoot")) { + Debug.Log("wow"); + RemoveMessage(); + } + } + + void RemoveMessage() { + GameObject.FindGameObjectsWithTag("Message")[0].GetComponent<SpriteRenderer>().enabled = false; + Time.timeScale = 1; + } +} diff --git a/Assets/Scripts/Upgrade.cs.meta b/Assets/Scripts/Upgrade.cs.meta new file mode 100644 index 0000000..76ce816 --- /dev/null +++ b/Assets/Scripts/Upgrade.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 6ebeab93d63674e3d9b10a8fc38418d3 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: |
