Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- boomerangScript.cs:
- 1: using System.Collections;
- 2: using System.Collections.Generic;
- 3: using UnityEngine;
- 4
- 5: public class boomerangScript : MonoBehaviour {
- 6: Transform t;
- 7: Rigidbody2D rb;
- 8
- 9: GameObject player;
- 10: GameObject trail;
- 11: Transform graphics;
- 12
- 13: string state = "thrown";
- 14
- 15: public float gravity;
- 16
- 17: public float turnAroundSpeed;
- 18: public float power;
- 19: public float throwPow;
- 20: public float direction;
- 21
- 22: float speed = 1;
- 23: public bool movingTowards = true;
- 24
- 25: public bool falling;
- 26: public bool hasHitFloor;
- 27
- 28: AudioSource[] sound;
- 29
- 30: void Start ()
- 31: {
- 32: cache();
- 33: setPower();
- 34
- 35: if (falling)
- 36: {
- 37: fallDown();
- 38: }
- 39: }
- 40
- 41: void cache()
- 42: {
- 43: t = transform;
- 44: rb = GetComponent<Rigidbody2D>();
- 45: trail = t.FindChild("trail").gameObject;
- 46: graphics = t.FindChild("graphics");
- 47: player = GameObject.Find("player");
- 48: sound = GetComponents<AudioSource>();
- 49: }
- 50
- 51: void setPower()
- 52: {
- 53: if (throwPow > 0 && throwPow < 0.05f)
- 54: {
- 55: throwPow = 0.05f;
- 56: }
- 57: power *= throwPow * direction * 12;
- 58: }
- 59
- 60: void Update ()
- 61: {
- 62: updateSpeed();
- 63: }
- 64
- 65: void updateSpeed()
- 66: {
- 67: if (movingTowards)
- 68: {
- 69: speed = Mathf.Lerp(speed, 0f, Time.deltaTime * turnAroundSpeed);
- 70: if (speed < 0.5f)
- 71: {
- 72: movingTowards = false;
- 73: }
- 74: }
- 75: else
- 76: {
- 77: speed = Mathf.Lerp(speed, -1f, Time.deltaTime * turnAroundSpeed);
- 78: }
- 79: }
- 80:
- 81: void FixedUpdate()
- 82: {
- 83: if (!falling)
- 84: {
- 85: move();
- 86: }
- 87: else if (falling && !hasHitFloor)
- 88: {
- 89: fall();
- 90: }
- 91: else if (hasHitFloor)
- 92: {
- 93: rb.velocity = Vector2.zero;
- 94: }
- 95: }
- 96
- 97: void move()
- 98: {
- 99: rb.velocity = new Vector2(speed * power,0);
- 100: graphics.Rotate(Vector3.forward * (speed * (3f+power) * 1.5f));
- 101: }
- 102
- 103: void OnCollisionEnter2D(Collision2D col)
- 104: {
- 105: if (!hasHitFloor && col.gameObject.tag == "solid")
- 106: {
- 107: if (!falling)
- 108: {
- 109: foreach (ContactPoint2D cp in col.contacts)
- 110: {
- 111: if (cp.point.x > t.position.x + .2f || cp.point.x < t.position.x - .2f)
- 112: {
- 113: sound[0].Play();
- 114: Camera.main.GetComponent<screenShake>().shake(0.1f, 0.01f * speed * power);
- 115: fallDown();
- 116: }
- 117: }
- 118: }
- 119: else
- 120: {
- 121: foreach (ContactPoint2D cp in col.contacts)
- 122: {
- 123: if (cp.point.y > t.position.y + .1f || cp.point.y < t.position.y - .1f)
- 124: {
- 125: Camera.main.GetComponent<screenShake>().shake(0.1f, 0.03f);
- 126: sound[0].Play();
- 127: hitFloor();
- 128: }
- 129: }
- 130: }
- 131: }
- 132: }
- 133
- 134: void fallDown()
- 135: {
- 136: trail.SetActive(false);
- 137: falling = true;
- 138: }
- 139
- 140: void fall()
- 141: {
- 142: float fallVel = (player.transform.position.x - t.position.x) / 5f;
- 143: if (Mathf.Abs(fallVel) > 5f)
- 144: {
- 145: fallVel = fallVel / Mathf.Abs(fallVel) * 5f;
- 146: }
- 147: rb.velocity = new Vector2(fallVel, rb.velocity.y-10*Time.deltaTime);
- 148: t.eulerAngles = new Vector3(0,0,Mathf.LerpAngle(t.eulerAngles.z, -45f, Time.deltaTime*5f));
- 149: }
- 150
- 151: void hitFloor()
- 152: {
- 153: hasHitFloor = true;
- 154: }
- 155: }
- destroyScript.cs:
- 1: using System.Collections;
- 2: using System.Collections.Generic;
- 3: using UnityEngine;
- 4
- 5: public class destroyScript : MonoBehaviour {
- 6: public float timer;
- 7:
- 8: void Update ()
- 9: {
- 10: timer -= Time.deltaTime;
- 11: if (timer < 0f)
- 12: {
- 13: Destroy(gameObject);
- 14: }
- 15: }
- 16: }
- 17
- effects\fadeOutScript.cs:
- 1: using System.Collections;
- 2: using System.Collections.Generic;
- 3: using UnityEngine;
- 4
- 5: public class fadeOutScript : MonoBehaviour {
- 6: public GameObject prefab;
- 7: public bool fadeIn;
- 8: public Texture2D white;
- 9: public float time;
- 10: float firstTime;
- 11: Color col;
- 12
- 13: void Start ()
- 14: {
- 15: col = Color.black;
- 16: if (!fadeIn)
- 17: {
- 18: col.a = 0f;
- 19: }
- 20
- 21: firstTime = time;
- 22: }
- 23:
- 24: void Update ()
- 25: {
- 26: time -= Time.deltaTime;
- 27
- 28: if (!fadeIn)
- 29: {
- 30: col.a = time / firstTime;
- 31: }
- 32: else
- 33: {
- 34: col.a = 1 - time / firstTime;
- 35: }
- 36
- 37
- 38: if (time < 0.01f && fadeIn)
- 39: {
- 40: Instantiate(prefab).GetComponent<fadeOutScript>().fadeIn = false;
- 41: }
- 42
- 43: if (time < 0)
- 44: {
- 45: Destroy(gameObject);
- 46: }
- 47: }
- 48
- 49: void OnGUI()
- 50: {
- 51: if (!fadeIn || time < firstTime - 0.1f)
- 52: {
- 53: GUI.color = col;
- 54: GUI.DrawTexture(new Rect(0, 0, Screen.width, Screen.height), white);
- 55: }
- 56: }
- 57: }
- 58
- effects\screenShake.cs:
- 1: using System.Collections;
- 2: using System.Collections.Generic;
- 3: using UnityEngine;
- 4
- 5: public class screenShake : MonoBehaviour {
- 6: Transform screen;
- 7: float shakeLeft;
- 8: float currentStrength;
- 9: public float maxScreenshake;
- 10
- 11: Vector3 origin;
- 12: void Start()
- 13: {
- 14: screen = Camera.main.transform;
- 15: }
- 16
- 17: public void shake(float t, float s)
- 18: {
- 19: if (currentStrength < maxScreenshake)
- 20: {
- 21: shakeLeft += t;
- 22: currentStrength /= 1.5f;
- 23: currentStrength += s;
- 24: origin = screen.position;
- 25: }
- 26: }
- 27
- 28: void FixedUpdate()
- 29: {
- 30: if (shakeLeft > 0)
- 31: {
- 32: screen.position = origin + (Vector3)new Vector2(Random.Range(-currentStrength, currentStrength), Random.Range(-currentStrength, currentStrength));
- 33: shakeLeft -= Time.fixedDeltaTime;
- 34: }
- 35: else
- 36: {
- 37: screen.position = new Vector3(0, 0, screen.position.z);
- 38: shakeLeft = 0;
- 39: }
- 40: }
- 41: }
- 42
- enemyDirectorScript.cs:
- 1: using System.Collections;
- 2: using System.Collections.Generic;
- 3: using UnityEngine;
- 4
- 5: public class enemyDirectorScript : MonoBehaviour {
- 6: public string[] possibleActions;
- 7:
- 8: void OnTriggerEnter2D (Collider2D col)
- 9: {
- 10: if (col.gameObject.tag == "enemy")
- 11: {
- 12: runnerEnemyScript runner = col.gameObject.GetComponent<runnerEnemyScript>();
- 13: runner.changeDirection(possibleActions);
- 14:
- 15: }
- 16: }
- 17: }
- enemySpawnerScript.cs:
- 1: using System.Collections;
- 2: using System.Collections.Generic;
- 3: using UnityEngine;
- 4
- 5: public class enemySpawnerScript : MonoBehaviour
- 6: {
- 7: public GameObject[] enemyTypes;
- 8: public Transform[] spawnPoints;
- 9
- 10: public Vector2 runnerFrq;
- 11
- 12: float difficulty;
- 13: float timeUntilRunner = 1f;
- 14
- 15: void Start ()
- 16: {
- 17
- 18: }
- 19
- 20: void setRunnerTime()
- 21: {
- 22: timeUntilRunner = Random.Range(runnerFrq.x, runnerFrq.y) / Mathf.Sqrt(Mathf.Sqrt(difficulty));
- 23: }
- 24:
- 25: void Update ()
- 26: {
- 27: difficulty += Time.deltaTime;
- 28
- 29: if (timeUntilRunner > 0)
- 30: {
- 31: timeUntilRunner -= Time.deltaTime;
- 32: }
- 33: else
- 34: {
- 35: spawnEnemy(0);
- 36: setRunnerTime();
- 37: }
- 38: }
- 39
- 40: void spawnEnemy(int type)
- 41: {
- 42: Instantiate(enemyTypes[type], spawnPoints[Random.Range(0, 2)].position, transform.rotation);
- 43: }
- 44: }
- 45
- gameManager.cs:
- 1: using System.Collections;
- 2: using System.Collections.Generic;
- 3: using UnityEngine;
- 4
- 5: public class gameManager : MonoBehaviour {
- 6
- 7: public TextMesh scorecounter;
- 8: int score = 0;
- 9: public GameObject fade;
- 10: float losetimer = -1;
- 11: public GameObject yousaved;
- 12
- 13: void Update()
- 14: {
- 15: updateGame();
- 16: }
- 17
- 18: //GAME
- 19: void newGame()
- 20: {
- 21: score = 0;
- 22: }
- 23:
- 24: public void getScore(int s)
- 25: {
- 26: score += s;
- 27: scorecounter.text = score.ToString();
- 28: }
- 29
- 30: public void lose()
- 31: {
- 32: fadeOutScript f = Instantiate(fade).GetComponent<fadeOutScript>();
- 33: f.fadeIn = true;
- 34: f.time = 1f;
- 35: losetimer = 1f;
- 36: }
- 37
- 38: void updateGame()
- 39: {
- 40: if (losetimer != -1)
- 41: {
- 42: losetimer -= Time.deltaTime;
- 43: if (losetimer < 0)
- 44: {
- 45: losetimer = -1;
- 46: GameObject s = Instantiate(yousaved);
- 47: s.GetComponent<savedThingScript>().savedThings = score;
- 48: DontDestroyOnLoad(s);
- 49: Application.LoadLevel("lose");
- 50: }
- 51: }
- 52: }
- 53: }
- 54
- playerScript.cs:
- 1: using System.Collections;
- 2: using System.Collections.Generic;
- 3: using UnityEngine;
- 4: using UnityEngine.UI;
- 5
- 6: public class playerScript : MonoBehaviour {
- 7: bool dead = false;
- 8
- 9: Transform t;
- 10: Rigidbody2D rb;
- 11: Animator animate;
- 12: SpriteRenderer sr;
- 13: BoxCollider2D bc;
- 14
- 15: LayerMask ignoreSelf;
- 16
- 17: public float movespeed;
- 18: public float accelerationBreaking;
- 19: public float gravity;
- 20: public float jumpHeight;
- 21: public float wallslideMultiplier;
- 22
- 23: float horKey;
- 24: [HideInInspector]
- 25: public bool jumpKey;
- 26: bool throwKey;
- 27
- 28: float currentGravity;
- 29: float currentJump;
- 30
- 31: Vector2 move;
- 32: public float movementMultiplier = 1;
- 33
- 34: bool floored;
- 35: bool roofed;
- 36: bool righted;
- 37: bool lefted;
- 38: bool walled;
- 39
- 40: bool lastFloored;
- 41: bool lastRoofed;
- 42
- 43: float aimDir;
- 44: public bool hasBoomerang;
- 45: public GameObject boomerangPrefab;
- 46: float boomerangCharge;
- 47
- 48: float justThrew;
- 49
- 50: public bool canJump;
- 51
- 52: AudioSource[] audio;
- 53
- 54: public GameObject deatheffect;
- 55
- 56: int health = 3;
- 57
- 58: public Sprite[] hearts;
- 59: public Image[] containers;
- 60
- 61: void Start ()
- 62: {
- 63: QualitySettings.vSyncCount = 0;
- 64: Application.targetFrameRate = 60;
- 65: cache();
- 66: }
- 67
- 68: void cache()
- 69: {
- 70: t = transform;
- 71: rb = GetComponent<Rigidbody2D>();
- 72: sr = GetComponent<SpriteRenderer>();
- 73: animate = GetComponent<Animator>();
- 74: bc = GetComponent<BoxCollider2D>();
- 75
- 76: audio = GetComponents<AudioSource>();
- 77: }
- 78:
- 79: void Update ()
- 80: {
- 81: if (!dead)
- 82: {
- 83: getInput();
- 84: hitHead();
- 85: setGravity();
- 86: setJump();
- 87: setMove();
- 88: checkThrowing();
- 89
- 90: animatePlayer();
- 91
- 92: if (t.position.y < -8.5f)
- 93: {
- 94: die();
- 95: }
- 96: }
- 97: }
- 98
- 99: void getInput ()
- 100: {
- 101: horKey = global.boolToFloat(Input.GetKey(KeyCode.RightArrow)) - global.boolToFloat(Input.GetKey(KeyCode.LeftArrow));
- 102: jumpKey = Input.GetKeyDown(KeyCode.X);
- 103: throwKey = Input.GetKey(KeyCode.C);
- 104
- 105: if (horKey != 0)
- 106: {
- 107: aimDir = horKey;
- 108: }
- 109: }
- 110
- 111: void setGroundedRoofed()
- 112: {
- 113: //floor
- 114: RaycastHit2D[] floorHit = Physics2D.BoxCastAll(t.position, bc.size, 0, -Vector2.up);
- 115: floored = false;
- 116: foreach (RaycastHit2D ray in floorHit)
- 117: {
- 118: if (ray && ray.collider.tag == "solid" && ray.distance < 0.1f)
- 119: {
- 120: floored = true;
- 121: }
- 122: }
- 123
- 124: if (floored != lastFloored && floored)
- 125: {
- 126: audio[4].Play();
- 127: }
- 128: lastFloored = floored;
- 129
- 130: //roof
- 131: RaycastHit2D[] roofHit = Physics2D.BoxCastAll(t.position, bc.size, 0, Vector2.up);
- 132: roofed = false;
- 133: foreach (RaycastHit2D ray in roofHit)
- 134: {
- 135: if (ray && ray.collider.tag == "solid" && ray.distance < 0.1f)
- 136: {
- 137: roofed = true;
- 138: }
- 139: }
- 140
- 141: if (roofed != lastRoofed && roofed)
- 142: {
- 143: audio[4].Play();
- 144: }
- 145: lastRoofed = roofed;
- 146
- 147: RaycastHit2D[] right = Physics2D.BoxCastAll(t.position, bc.size, 0, Vector2.right);
- 148: righted = false;
- 149: foreach (RaycastHit2D ray in right)
- 150: {
- 151: if (ray && ray.collider.tag == "solid" && ray.distance < 0.1f)
- 152: {
- 153: righted = true;
- 154: }
- 155: }
- 156
- 157: RaycastHit2D[] left = Physics2D.BoxCastAll(t.position, bc.size, 0, Vector2.left);
- 158: lefted = false;
- 159: foreach (RaycastHit2D ray in left)
- 160: {
- 161: if (ray && ray.collider.tag == "solid" && ray.distance < 0.1f)
- 162: {
- 163: lefted = true;
- 164: }
- 165: }
- 166:
- 167: walled = lefted || righted;
- 168: }
- 169
- 170: void setGravity ()
- 171: {
- 172: if (!floored)
- 173: {
- 174: float curModGrav = gravity;
- 175: if (walled && currentGravity > 0)
- 176: {
- 177: curModGrav *= wallslideMultiplier;
- 178: }
- 179: currentGravity += curModGrav * Time.deltaTime * 60f;
- 180: }
- 181: else if (!roofed && currentGravity > 0)
- 182: {
- 183: currentGravity = 0;
- 184: }
- 185: }
- 186
- 187: void hitHead ()
- 188: {
- 189: if (roofed && !floored && currentGravity < 0)
- 190: {
- 191: currentGravity = 0.1f;
- 192: }
- 193: }
- 194
- 195: void setJump ()
- 196: {
- 197: if (jumpKey && floored && canJump)
- 198: {
- 199: audio[0].Play();
- 200: currentGravity = -jumpHeight * 100;
- 201: }
- 202: canJump = true;
- 203: }
- 204
- 205: void setMove ()
- 206: {
- 207: move.x = Mathf.Lerp(move.x, horKey*movespeed, Time.deltaTime * accelerationBreaking);
- 208: move.y = -currentGravity*Time.deltaTime;
- 209: }
- 210
- 211: void checkThrowing ()
- 212: {
- 213: if (justThrew > 0)
- 214: {
- 215: justThrew -= Time.deltaTime;
- 216: }
- 217: else
- 218: {
- 219: justThrew = 0;
- 220: }
- 221
- 222: if (throwKey && hasBoomerang)
- 223: {
- 224: Time.timeScale = 0.2f;
- 225: movementMultiplier = 0;
- 226: currentGravity = 2;
- 227: horKey = 0;
- 228: chargeUpThrow();
- 229: }
- 230: else
- 231: {
- 232: if (boomerangCharge > 0)
- 233: {
- 234: throwBoomerang();
- 235: }
- 236: Time.timeScale = 1f;
- 237: movementMultiplier = 1;
- 238: }
- 239: }
- 240
- 241: void chargeUpThrow()
- 242: {
- 243: if (hasBoomerang)
- 244: {
- 245: boomerangCharge += Time.deltaTime;
- 246: audio[2].Play();
- 247: audio[2].pitch = 1f + boomerangCharge * 20;
- 248: if (boomerangCharge > 0.10f)
- 249: {
- 250: throwBoomerang();
- 251: }
- 252: }
- 253: }
- 254
- 255: void throwBoomerang()
- 256: {
- 257: audio[1].Play();
- 258: Camera.main.GetComponent<screenShake>().shake(0.1f, 0.1f);
- 259: GameObject boomerang = Instantiate(boomerangPrefab, t.position, t.rotation);
- 260: boomerangScript boomerangScr = boomerang.GetComponent<boomerangScript>();
- 261: boomerangScr.direction = aimDir;
- 262: boomerangScr.throwPow = boomerangCharge;
- 263: boomerangCharge = 0f;
- 264: hasBoomerang = false;
- 265: justThrew = 0.1f;
- 266: }
- 267
- 268: void FixedUpdate ()
- 269: {
- 270: setGroundedRoofed();
- 271: setMove();
- 272: movePlayer();
- 273: }
- 274
- 275: void movePlayer()
- 276: {
- 277: rb.velocity = move * movementMultiplier;
- 278: }
- 279
- 280: void OnTriggerEnter2D(Collider2D col)
- 281: {
- 282: if (col.tag == "enemy")
- 283: {
- 284: runnerEnemyScript runner = col.GetComponent<runnerEnemyScript>();
- 285: if (runner)
- 286: {
- 287: runner.die();
- 288: }
- 289: hurt();
- 290: }
- 291: }
- 292
- 293: void OnTriggerStay2D(Collider2D col)
- 294: {
- 295: if (col.gameObject.tag == "boomerang")
- 296: {
- 297: catchBoomerang(col.gameObject);
- 298: }
- 299: }
- 300
- 301: void catchBoomerang(GameObject boom)
- 302: {
- 303: if (!boom.GetComponent<boomerangScript>().movingTowards)
- 304: {
- 305: audio[3].Play();
- 306: Destroy(boom);
- 307: hasBoomerang = true;
- 308: }
- 309: }
- 310
- 311: void animatePlayer()
- 312: {
- 313: sr.flipX = (aimDir < 0);
- 314
- 315: if (justThrew > 0)
- 316: {
- 317: animate.Play("throw");
- 318: }
- 319: else if (boomerangCharge != 0)
- 320: {
- 321: animate.Play("charging");
- 322: }
- 323: else if (move.y != 0)
- 324: {
- 325: if (move.y > 0)
- 326: {
- 327: animate.Play("jumping animation");
- 328: }
- 329: else
- 330: {
- 331: animate.Play("fall animation");
- 332: }
- 333: sr.flipX = false;
- 334: }
- 335: else if (Mathf.Abs(move.x) > movespeed / 3)
- 336: {
- 337: animate.Play("running animation");
- 338: }
- 339: else
- 340: {
- 341: animate.Play("idle animation");
- 342: }
- 343: }
- 344
- 345: void hurt()
- 346: {
- 347: health -= 1;
- 348: if (health <= 0)
- 349: {
- 350: die();
- 351: }
- 352: Camera.main.GetComponent<screenShake>().shake(0.2f, 0.5f);
- 353: audio[5].Play();
- 354: Time.timeScale = 1f;
- 355
- 356: updateHeartContainers();
- 357: }
- 358
- 359: void die()
- 360: {
- 361: Camera.main.GetComponent<screenShake>().shake(0.2f, 0.5f);
- 362: Time.timeScale = 1f;
- 363: Instantiate(deatheffect, t.position, t.rotation);
- 364: GetComponent<Renderer>().enabled = false;
- 365: GameObject.Find("always").GetComponent<gameManager>().lose();
- 366: dead = true;
- 367: }
- 368
- 369: void updateHeartContainers()
- 370: {
- 371: foreach (Image c in containers)
- 372: {
- 373: c.sprite = hearts[1];
- 374: }
- 375
- 376: for(int i = 0; i < health; i++)
- 377: {
- 378: containers[i].sprite = hearts[0];
- 379: }
- 380: }
- 381: }
- portalScript.cs:
- 1: using System.Collections;
- 2: using System.Collections.Generic;
- 3: using UnityEngine;
- 4
- 5: public class portalScript : MonoBehaviour {
- 6: Transform t;
- 7: public float basesize;
- 8: public float offset;
- 9
- 10: float extrasize;
- 11
- 12: void Start ()
- 13: {
- 14: t = transform;
- 15: offset = Random.Range(-offset, offset);
- 16: }
- 17:
- 18: void Update ()
- 19: {
- 20: t.localScale = new Vector3(basesize+Mathf.Cos(Time.time*3+offset)/10+extrasize, basesize+Mathf.Sin(Time.time*3+offset)/10+extrasize, 0);
- 21
- 22: extrasize = Mathf.Lerp(extrasize, 0, Time.deltaTime * 3);
- 23: }
- 24
- 25: public void usePortal()
- 26: {
- 27: extrasize = 0.2f;
- 28: }
- 29: }
- 30
- roomManager.cs:
- 1: using System.Collections;
- 2: using System.Collections.Generic;
- 3: using UnityEngine;
- 4
- 5: public class roomManager : MonoBehaviour {
- 6: public GameObject cover;
- 7: public Transform rooms;
- 8: GameObject activeRoom;
- 9:
- 10: void Start()
- 11: {
- 12: findActiveRoom();
- 13: }
- 14
- 15: void findActiveRoom()
- 16: {
- 17: for (int i = 0; i < rooms.childCount; i++)
- 18: {
- 19: Transform room = rooms.GetChild(i);
- 20: if (room.gameObject.activeSelf)
- 21: {
- 22: activeRoom = room.gameObject;
- 23: }
- 24: }
- 25: }
- 26
- 27: public void startRoomLoad(string roomName)
- 28: {
- 29: loadRoom(roomName);
- 30: }
- 31
- 32: public void loadRoom (string roomName)
- 33: {
- 34: activeRoom.SetActive(false);
- 35: activeRoom = rooms.FindChild(roomName).gameObject;
- 36: activeRoom.SetActive(true);
- 37: }
- 38: }
- 39
- runnerEnemyScript.cs:
- 1: using System.Collections;
- 2: using System.Collections.Generic;
- 3: using UnityEngine;
- 4
- 5: public class runnerEnemyScript : MonoBehaviour {
- 6: Transform t;
- 7: Rigidbody2D rb;
- 8: BoxCollider2D bc;
- 9
- 10: [HideInInspector]
- 11: public float runningDirection;
- 12
- 13: //prefabs
- 14: public GameObject explosionPrefab;
- 15
- 16: //stats
- 17: public float runningSpeed;
- 18: public float gravity;
- 19: public float jump;
- 20
- 21: //vars
- 22: float currentGravity;
- 23: Vector2 move;
- 24: bool waitingForJump;
- 25
- 26: float wantedHorMove;
- 27: float horMove;
- 28
- 29: void Start ()
- 30: {
- 31: t = transform;
- 32: rb = GetComponent<Rigidbody2D>();
- 33: bc = GetComponent<BoxCollider2D>();
- 34
- 35: runningSpeed *= Random.Range(1f, 1.2f);
- 36: }
- 37:
- 38: void Update ()
- 39: {
- 40: setGravity();
- 41: setMove();
- 42: checkDead();
- 43: //turnOnHit();
- 44: }
- 45
- 46: public void changeDirection(string[] possibleMove)
- 47: {
- 48: string toMove = possibleMove[Random.Range(0,possibleMove.Length)];
- 49
- 50: if (toMove == "left")
- 51: {
- 52: runningDirection = -1f;
- 53: }
- 54: else if (toMove == "right")
- 55: {
- 56: runningDirection = 1f;
- 57: }
- 58: else if (toMove == "jump right")
- 59: {
- 60: waitingForJump = true;
- 61: runningDirection = 1f;
- 62: }
- 63: else if (toMove == "jump left")
- 64: {
- 65: waitingForJump = true;
- 66: runningDirection = -1f;
- 67: }
- 68: else if (toMove == "")
- 69: {
- 70: runningDirection = 0;
- 71: waitingForJump = false;
- 72: }
- 73: }
- 74
- 75: void FixedUpdate()
- 76: {
- 77: moveObject();
- 78: }
- 79
- 80: void setGravity()
- 81: {
- 82: RaycastHit2D[] floorHit = Physics2D.BoxCastAll(t.position, bc.size, 0, -Vector2.up);
- 83: bool floored = false;
- 84: foreach (RaycastHit2D ray in floorHit)
- 85: {
- 86: if (ray && ray.collider.tag == "solid" && ray.distance < 0.06f)
- 87: {
- 88: floored = true;
- 89: }
- 90: }
- 91
- 92: if (!floored)
- 93: {
- 94: currentGravity += Time.deltaTime * gravity;
- 95: }
- 96: else if (currentGravity > 0)
- 97: {
- 98: if (waitingForJump)
- 99: {
- 100: currentGravity = -jump;
- 101: waitingForJump = false;
- 102: }
- 103: else
- 104: {
- 105: currentGravity = 0;
- 106: }
- 107: }
- 108: }
- 109
- 110: void turnOnHit()
- 111: {
- 112: if (runningDirection > 0)
- 113: {
- 114: RaycastHit2D[] rightHit = Physics2D.BoxCastAll(t.position, bc.size, 0, Vector2.right);
- 115: foreach (RaycastHit2D ray in rightHit)
- 116: {
- 117: if (ray && ray.collider.tag == "solid" && ray.distance < 0.1f)
- 118: {
- 119: runningDirection = -runningDirection;
- 120: }
- 121: }
- 122: }
- 123: else
- 124: {
- 125: RaycastHit2D[] leftHit = Physics2D.BoxCastAll(t.position, bc.size * 0.9f, 0, Vector2.left);
- 126: foreach (RaycastHit2D ray in leftHit)
- 127: {
- 128: if (ray && ray.collider.tag == "solid" && ray.distance < 0.1f)
- 129: {
- 130: runningDirection = -runningDirection;
- 131: }
- 132: }
- 133: }
- 134: }
- 135
- 136: void setMove()
- 137: {
- 138: wantedHorMove = runningDirection * runningSpeed;
- 139: horMove = Mathf.Lerp(wantedHorMove, horMove, Time.deltaTime * 7f);
- 140: move = new Vector2(horMove, -currentGravity);
- 141: }
- 142
- 143: void moveObject()
- 144: {
- 145: rb.velocity = move;
- 146: }
- 147
- 148: void OnTriggerEnter2D(Collider2D col)
- 149: {
- 150: if (col.tag == "boomerang")
- 151: {
- 152: if (!col.GetComponent<boomerangScript>().hasHitFloor)
- 153: getHit();
- 154: }
- 155: }
- 156
- 157: void checkDead()
- 158: {
- 159: if (t.position.y < -8.5f)
- 160: {
- 161: die();
- 162: }
- 163: }
- 164
- 165: void getHit()
- 166: {
- 167: GameObject.Find("always").GetComponent<gameManager>().getScore(1);
- 168: die();
- 169: }
- 170
- 171: public void die()
- 172: {
- 173: Instantiate(explosionPrefab, t.position, t.rotation);
- 174: Destroy(gameObject);
- 175: }
- 176: }
- 177
- savedThingScript.cs:
- 1: using System.Collections;
- 2: using System.Collections.Generic;
- 3: using UnityEngine;
- 4
- 5: public class savedThingScript : MonoBehaviour {
- 6: public int savedThings;
- 7
- 8: void Update ()
- 9: {
- 10: if (Application.loadedLevelName == "lose")
- 11: {
- 12: GameObject.Find("you saved").GetComponent<TextMesh>().text = "You saved "+savedThings+" green things!";
- 13: Destroy(gameObject);
- 14: }
- 15: }
- 16: }
- 17
- stateManagerScript.cs:
- 1: using System.Collections;
- 2: using System.Collections.Generic;
- 3: using UnityEngine;
- 4
- 5: public class stateManagerScript : MonoBehaviour {
- 6: GameObject cur;
- 7
- 8: public GameObject menu;
- 9: public GameObject game;
- 10
- 11: void Start ()
- 12: {
- 13: setState("menu");
- 14: }
- 15
- 16: public void setState(string s)
- 17: {
- 18: print(s);
- 19: if (s == "game")
- 20: {
- 21: cur = Instantiate(game);
- 22: }
- 23: else if (s == "menu")
- 24: {
- 25: cur = Instantiate(menu);
- 26: }
- 27: }
- 28:
- 29: void Update ()
- 30: {
- 31:
- 32: }
- 33: }
- 34
- targetScript.cs:
- 1: using System.Collections;
- 2: using System.Collections.Generic;
- 3: using UnityEngine;
- 4
- 5: public class targetScript : MonoBehaviour {
- 6: public GameObject explosion;
- 7: void OnTriggerEnter2D (Collider2D col)
- 8: {
- 9: if (col.tag == "boomerang")
- 10: {
- 11: die();
- 12: }
- 13: }
- 14
- 15: void die()
- 16: {
- 17: Camera.main.GetComponent<screenShake>().shake(0.1f, 0.3f);
- 18: Transform e = Instantiate(explosion, transform.position, transform.rotation).transform;
- 19: e.parent = null;
- 20: Destroy(gameObject);
- 21: }
- 22: }
- 23
- terminalScript.cs:
- 1: using System.Collections;
- 2: using System.Collections.Generic;
- 3: using UnityEngine;
- 4
- 5: public class terminalScript : MonoBehaviour {
- 6
- 7: public GameObject screen;
- 8: public GameObject press;
- 9: public playerScript player;
- 10
- 11: bool hasBoom;
- 12: bool isInside;
- 13: bool hasPressed;
- 14: bool hasDialoged;
- 15: bool hasQuit;
- 16
- 17: [TextArea(3,5)]
- 18: public string[] screenSay;
- 19
- 20: float timeToScreenshake = -1;
- 21
- 22: void Start()
- 23: {
- 24: player = GameObject.Find("player").GetComponent<playerScript>();
- 25: }
- 26
- 27: void Update()
- 28: {
- 29: if (isInside && !hasPressed)
- 30: {
- 31: player.canJump = false;
- 32: if (player.jumpKey)
- 33: {
- 34: pressed();
- 35: }
- 36: }
- 37
- 38: if (screen.GetComponent<textboxScript>().diagloging)
- 39: {
- 40: GameObject.Find("player").GetComponent<playerScript>().movementMultiplier = 0f;
- 41: hasDialoged = true;
- 42: }
- 43:
- 44: if (timeToScreenshake != -1)
- 45: {
- 46: timeToScreenshake -= Time.deltaTime;
- 47: if (timeToScreenshake < 0)
- 48: {
- 49: Camera.main.GetComponent<screenShake>().shake(0.5f, 0.3f);
- 50: GameObject.Find("always").GetComponent<roomManager>().startRoomLoad("room 2");
- 51: timeToScreenshake = -1;
- 52: }
- 53: }
- 54: }
- 55
- 56: void pressed()
- 57: {
- 58: timeToScreenshake = 6f;
- 59: screen.GetComponent<textboxScript>().set(screenSay);
- 60: press.SetActive(false);
- 61: hasPressed = true;
- 62: player.canJump = true;
- 63: }
- 64
- 65: void OnTriggerStay2D (Collider2D col)
- 66: {
- 67: if (col.gameObject.tag == "player" && !hasPressed)
- 68: {
- 69: press.SetActive(true);
- 70: isInside = true;
- 71: }
- 72: }
- 73
- 74: void OnTriggerExit2D (Collider2D col)
- 75: {
- 76: if (col.gameObject.tag == "player")
- 77: {
- 78: press.SetActive(false);
- 79: }
- 80: isInside = false;
- 81: }
- 82: }
- 83
- wrapScript.cs:
- 1: using System.Collections;
- 2: using System.Collections.Generic;
- 3: using UnityEngine;
- 4
- 5: public class wrapScript : MonoBehaviour {
- 6: Transform t;
- 7: public bool cantWrapVer;
- 8: void Start ()
- 9: {
- 10: t = transform;
- 11: }
- 12:
- 13: void Update ()
- 14: {
- 15: if (t.position.x > 11.5)
- 16: {
- 17: t.position = new Vector3(-11.4f, t.position.y, t.position.z);
- 18: trigger();
- 19: }
- 20: else if (t.position.x < -12)
- 21: {
- 22: t.position = new Vector3(11.4f, t.position.y, t.position.z);
- 23: trigger();
- 24: }
- 25
- 26: if (!cantWrapVer)
- 27: {
- 28: if (t.position.y < -8.5f)
- 29: {
- 30: t.position = new Vector3(t.position.x, 8.5f, t.position.z);
- 31: }
- 32: }
- 33: }
- 34
- 35: void trigger()
- 36: {
- 37: GameObject.Find("portal sound").GetComponent<AudioSource>().Play();
- 38
- 39: GameObject portalObj = GameObject.Find("right portal");
- 40: portalObj.GetComponent<portalScript>().usePortal();
- 41: portalScript[] portals = portalObj.GetComponentsInChildren<portalScript>();
- 42: foreach (portalScript p in portals)
- 43: {
- 44: p.usePortal();
- 45: }
- 46
- 47: portalObj = GameObject.Find("left portal");
- 48: portalObj.GetComponent<portalScript>().usePortal();
- 49: portals = portalObj.GetComponentsInChildren<portalScript>();
- 50: foreach (portalScript p in portals)
- 51: {
- 52: p.usePortal();
- 53: }
- 54: }
- 55: }
- 56
- global.cs:
- 1: using UnityEngine;
- 2: using System.Collections;
- 3
- 4: public class global {
- 5
- 6: public static string alphabet = "abcdefghijklmnopqrstuvwxyz";
- 7
- 8: public static float boolToFloat(bool b)
- 9: {
- 10: if (b)
- 11: {
- 12: return 1f;
- 13: }
- 14: return 0f;
- 15: }
- 16
- 17: public static Vector2 angleToVector2(float angle)
- 18: {
- 19: return (Vector2)(Quaternion.Euler(0, 0, angle) * Vector2.right);
- 20: }
- 21
- 22: public static float vector2ToAngle(Vector2 v2End, Vector2 v2Start)
- 23: {
- 24: Vector2 v2 = v2End - v2Start;
- 25: return normalizeRotation(180f+Mathf.Atan2(v2.y, v2.x) * Mathf.Rad2Deg);
- 26: }
- 27
- 28: public static float normalizeRotation(float rotation)
- 29: {
- 30: if (rotation > 360f)
- 31: {
- 32: do
- 33: {
- 34: rotation -= 360f;
- 35: } while (rotation >= 360f);
- 36: }
- 37: else if (rotation < 1f)
- 38: {
- 39: do
- 40: {
- 41: rotation += 360f;
- 42: } while (rotation <= 0f);
- 43: }
- 44: return rotation;
- 45: }
- 46
- 47: public static bool isBetween(float a, float min, float max)
- 48: {
- 49: if ((a < max && a > min) || (a > max && a < min))
- 50: {
- 51: return true;
- 52: }
- 53: return false;
- 54: }
- 55: }
- 56
- cubeScript.cs:
- 1: using UnityEngine;
- 2: using System.Collections;
- 3
- 4: public class cubeScript : MonoBehaviour {
- 5
- 6: Transform t;
- 7: float firstTimer = 1;
- 8
- 9: void Start ()
- 10: {
- 11: t = transform;
- 12: }
- 13
- 14: void Update ()
- 15: {
- 16: if (Time.time < 1)
- 17: {
- 18: firstTimer += Time.deltaTime * 2;
- 19: t.Translate (Vector3.down * 3 * Time.deltaTime * firstTimer);
- 20: }
- 21: else if (Time.time < 2)
- 22: {
- 23: t.rotation = Quaternion.Lerp (t.rotation, Quaternion.Euler (new Vector3 (45, 45, 0)), Time.deltaTime * 5);
- 24: }
- 25: else if (Time.time < 2.1)
- 26: {
- 27: t.rotation = Quaternion.Euler (new Vector3 (45, 45, 0));
- 28: }
- 29: else if (Time.time > 2.5)
- 30: {
- 31: Application.LoadLevel(1);
- 32: }
- 33: }
- 34: }
- flashScript.cs:
- 1: using UnityEngine;
- 2: using System.Collections;
- 3
- 4: public class flashScript : MonoBehaviour {
- 5: Transform t;
- 6: float flashTimer = 0;
- 7: void Start () {
- 8: gameObject.GetComponent<Renderer> ().material.color = Color.white;
- 9: }
- 10: void Update () {
- 11: if (Time.time > 1.7f && Time.time < 1.85f) {
- 12: if (flashTimer < 0) {
- 13: if (gameObject.GetComponent<Renderer> ().material.color == Color.white) {
- 14: gameObject.GetComponent<Renderer> ().material.color = Color.black;
- 15: } else {
- 16: gameObject.GetComponent<Renderer> ().material.color = Color.white;
- 17: }
- 18: flashTimer = 0.005f;
- 19: }
- 20: flashTimer -= Time.deltaTime;
- 21: } else if (Time.time > 1.7f) {
- 22: gameObject.GetComponent<Renderer> ().material.color = Color.black;
- 23: }
- 24: }
- 25: }
- textboxScript.cs:
- 1: using System.Collections;
- 2: using System.Collections.Generic;
- 3: using UnityEngine;
- 4
- 5: public class textboxScript : MonoBehaviour
- 6: {
- 7
- 8: //Variables:
- 9
- 10: //Cached components [var]
- 11: TextMesh text;
- 12: AudioSource sound;
- 13
- 14: //Stats [var]
- 15: public float timeBetweenCharacters;
- 16: public float toneNormalization;
- 17
- 18: //Current variables [var]
- 19: string[] textboxQueue;
- 20: string written;
- 21: int currentBox;
- 22: int currentCharacter;
- 23: float timeUntilNextCharacter;
- 24
- 25: public bool diagloging;
- 26: bool canWrite;
- 27
- 28
- 29
- 30: //Functions:
- 31
- 32: //Start [>]
- 33: void Start()
- 34: {
- 35: cache();
- 36: disableBox();
- 37: }
- 38
- 39: //Cache [>]
- 40: void cache()
- 41: {
- 42: text = GetComponent<TextMesh>();
- 43: sound = GetComponent<AudioSource>();
- 44: }
- 45:
- 46: //Set boxes [>>]
- 47: public void set(string[] newQueue)
- 48: {
- 49: textboxQueue = newQueue;
- 50: currentBox = -1;
- 51
- 52: diagloging = true;
- 53: canWrite = true;
- 54:
- 55: text.text = "";
- 56
- 57: startNewBox();
- 58: }
- 59
- 60: //Update [>]
- 61: void Update ()
- 62: {
- 63: if (diagloging)
- 64: {
- 65: writeBox();
- 66: }
- 67: }
- 68
- 69: //Start new box [>]
- 70: void startNewBox ()
- 71: {
- 72: currentCharacter = 0;
- 73: currentBox += 1;
- 74: written = "";
- 75: timeUntilNextCharacter = 0f;
- 76
- 77: if (currentBox >= textboxQueue.Length)
- 78: {
- 79: disableBox();
- 80: }
- 81: }
- 82
- 83: //Write current box [>]
- 84: void writeBox ()
- 85: {
- 86: if (canWrite)
- 87: {
- 88: if (timeUntilNextCharacter > 0f)
- 89: {
- 90: timeUntilNextCharacter -= Time.deltaTime;
- 91: }
- 92: else if (currentCharacter < textboxQueue[currentBox].Length)
- 93: {
- 94: writeLetter();
- 95: }
- 96: else
- 97: {
- 98: startNewBox();
- 99: }
- 100: }
- 101: }
- 102
- 103: void writeLetter()
- 104: {
- 105: currentCharacter += 1;
- 106
- 107: string thisChar;
- 108: if (currentCharacter < textboxQueue[currentBox].Length)
- 109: {
- 110: thisChar = textboxQueue[currentBox].Substring(currentCharacter, 1);
- 111: }
- 112: else
- 113: {
- 114: thisChar = "";
- 115: }
- 116
- 117: written = textboxQueue[currentBox].Insert(currentCharacter, "<color=#ffffff00>");
- 118: written = written.Insert(written.Length, "</color>");
- 119: timeUntilNextCharacter = timeBetweenCharacters;
- 120
- 121: //play sound
- 122: int letterIndex = global.alphabet.IndexOf(thisChar);
- 123: if (letterIndex > -1)
- 124: {
- 125: sound.pitch = 1f + ((float)letterIndex - 13) / 26f / toneNormalization;
- 126: sound.Play();
- 127: }
- 128
- 129: updateBox();
- 130: }
- 131
- 132: void updateBox()
- 133: {
- 134: text.text = written;
- 135: }
- 136
- 137: //Disable box
- 138: void disableBox()
- 139: {
- 140: diagloging = false;
- 141: canWrite = false;
- 142: }
- 143: }
- 144
- globalControlScript.cs:
- 1: using System.Collections;
- 2: using System.Collections.Generic;
- 3: using UnityEngine;
- 4
- 5: public class globalControlScript : MonoBehaviour {
- 6: void Start ()
- 7: {
- 8: DontDestroyOnLoad(gameObject);
- 9: }
- 10
- 11: void Update ()
- 12: {
- 13: if (Input.GetKeyDown(KeyCode.Escape))
- 14: {
- 15: Application.Quit();
- 16: }
- 17: }
- 18: }
- 19
- menuScript.cs:
- 1: using System.Collections;
- 2: using System.Collections.Generic;
- 3: using UnityEngine;
- 4
- 5: public class menuScript : MonoBehaviour {
- 6: public GameObject fade;
- 7: float timer = -1;
- 8
- 9: public string toLoad;
- 10:
- 11: void Update ()
- 12: {
- 13: if (Input.GetKeyDown(KeyCode.X) && timer == -1)
- 14: {
- 15: Instantiate(fade);
- 16: timer = 1;
- 17: }
- 18
- 19: if (timer > 0)
- 20: {
- 21: timer -= Time.deltaTime;
- 22: }
- 23: else if (timer < 0 && timer > -1f)
- 24: {
- 25: Application.LoadLevel(toLoad);
- 26: }
- 27: }
- 28: }
- 29
Add Comment
Please, Sign In to add comment