Guest User

https://pixzleone.itch.io/boomerangboy source

a guest
Dec 12th, 2016
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 45.00 KB | None | 0 0
  1. boomerangScript.cs:
  2.     1: using System.Collections;
  3.     2: using System.Collections.Generic;
  4.     3: using UnityEngine;
  5.     4  
  6.     5: public class boomerangScript : MonoBehaviour {
  7.     6:     Transform t;
  8.     7:     Rigidbody2D rb;
  9.     8  
  10.     9:     GameObject player;
  11.    10:     GameObject trail;
  12.    11:     Transform graphics;
  13.    12  
  14.    13:     string state = "thrown";
  15.    14  
  16.    15:     public float gravity;
  17.    16  
  18.    17:     public float turnAroundSpeed;
  19.    18:     public float power;
  20.    19:     public float throwPow;
  21.    20:     public float direction;
  22.    21  
  23.    22:     float speed = 1;
  24.    23:     public bool movingTowards = true;
  25.    24  
  26.    25:     public bool falling;
  27.    26:     public bool hasHitFloor;
  28.    27  
  29.    28:     AudioSource[] sound;
  30.    29  
  31.    30:  void Start ()
  32.    31:     {
  33.    32:         cache();
  34.    33:         setPower();
  35.    34  
  36.    35:         if (falling)
  37.    36:         {
  38.    37:             fallDown();
  39.    38:         }
  40.    39:  }
  41.    40  
  42.    41:     void cache()
  43.    42:     {
  44.    43:         t = transform;
  45.    44:         rb = GetComponent<Rigidbody2D>();
  46.    45:         trail = t.FindChild("trail").gameObject;
  47.    46:         graphics = t.FindChild("graphics");
  48.    47:         player = GameObject.Find("player");
  49.    48:         sound = GetComponents<AudioSource>();
  50.    49:     }
  51.    50  
  52.    51:     void setPower()
  53.    52:     {
  54.    53:         if (throwPow > 0 && throwPow < 0.05f)
  55.    54:         {
  56.    55:             throwPow = 0.05f;
  57.    56:         }
  58.    57:         power *= throwPow * direction * 12;
  59.    58:     }
  60.    59  
  61.    60:  void Update ()
  62.    61:     {
  63.    62:         updateSpeed();
  64.    63:  }
  65.    64  
  66.    65:     void updateSpeed()
  67.    66:     {
  68.    67:         if (movingTowards)
  69.    68:         {
  70.    69:             speed = Mathf.Lerp(speed, 0f, Time.deltaTime * turnAroundSpeed);
  71.    70:             if (speed < 0.5f)
  72.    71:             {
  73.    72:                 movingTowards = false;
  74.    73:             }
  75.    74:         }
  76.    75:         else
  77.    76:         {
  78.    77:             speed = Mathf.Lerp(speed, -1f, Time.deltaTime * turnAroundSpeed);
  79.    78:         }
  80.    79:     }
  81.    80:    
  82.    81:     void FixedUpdate()
  83.    82:     {
  84.    83:         if (!falling)
  85.    84:         {
  86.    85:             move();
  87.    86:         }
  88.    87:         else if (falling && !hasHitFloor)
  89.    88:         {
  90.    89:             fall();
  91.    90:         }
  92.    91:         else if (hasHitFloor)
  93.    92:         {
  94.    93:             rb.velocity = Vector2.zero;
  95.    94:         }
  96.    95:     }
  97.    96  
  98.    97:     void move()
  99.    98:     {
  100.    99:         rb.velocity = new Vector2(speed * power,0);
  101.   100:         graphics.Rotate(Vector3.forward * (speed * (3f+power) * 1.5f));
  102.   101:     }
  103.   102  
  104.   103:     void OnCollisionEnter2D(Collision2D col)
  105.   104:     {
  106.   105:         if (!hasHitFloor && col.gameObject.tag == "solid")
  107.   106:         {
  108.   107:             if (!falling)
  109.   108:             {
  110.   109:                 foreach (ContactPoint2D cp in col.contacts)
  111.   110:                 {
  112.   111:                     if (cp.point.x > t.position.x + .2f || cp.point.x < t.position.x - .2f)
  113.   112:                     {
  114.   113:                         sound[0].Play();
  115.   114:                         Camera.main.GetComponent<screenShake>().shake(0.1f, 0.01f * speed * power);
  116.   115:                         fallDown();
  117.   116:                     }
  118.   117:                 }
  119.   118:             }
  120.   119:             else
  121.   120:             {
  122.   121:                 foreach (ContactPoint2D cp in col.contacts)
  123.   122:                 {
  124.   123:                     if (cp.point.y > t.position.y + .1f || cp.point.y < t.position.y - .1f)
  125.   124:                     {
  126.   125:                         Camera.main.GetComponent<screenShake>().shake(0.1f, 0.03f);
  127.   126:                         sound[0].Play();
  128.   127:                         hitFloor();
  129.   128:                     }
  130.   129:                 }
  131.   130:             }
  132.   131:         }
  133.   132:     }
  134.   133  
  135.   134:     void fallDown()
  136.   135:     {
  137.   136:         trail.SetActive(false);
  138.   137:         falling = true;
  139.   138:     }
  140.   139  
  141.   140:     void fall()
  142.   141:     {
  143.   142:         float fallVel = (player.transform.position.x - t.position.x) / 5f;
  144.   143:         if (Mathf.Abs(fallVel) > 5f)
  145.   144:         {
  146.   145:             fallVel = fallVel / Mathf.Abs(fallVel) * 5f;
  147.   146:         }
  148.   147:         rb.velocity = new Vector2(fallVel, rb.velocity.y-10*Time.deltaTime);
  149.   148:         t.eulerAngles = new Vector3(0,0,Mathf.LerpAngle(t.eulerAngles.z, -45f, Time.deltaTime*5f));
  150.   149:     }
  151.   150  
  152.   151:     void hitFloor()
  153.   152:     {
  154.   153:         hasHitFloor = true;
  155.   154:     }
  156.   155: }
  157.  
  158. destroyScript.cs:
  159.     1: using System.Collections;
  160.     2: using System.Collections.Generic;
  161.     3: using UnityEngine;
  162.     4  
  163.     5: public class destroyScript : MonoBehaviour {
  164.     6:     public float timer;
  165.     7:  
  166.     8:  void Update ()
  167.     9:     {
  168.    10:         timer -= Time.deltaTime;
  169.    11:         if (timer < 0f)
  170.    12:         {
  171.    13:             Destroy(gameObject);
  172.    14:         }
  173.    15:  }
  174.    16: }
  175.    17  
  176.  
  177. effects\fadeOutScript.cs:
  178.     1: using System.Collections;
  179.     2: using System.Collections.Generic;
  180.     3: using UnityEngine;
  181.     4  
  182.     5: public class fadeOutScript : MonoBehaviour {
  183.     6:     public GameObject prefab;
  184.     7:     public bool fadeIn;
  185.     8:     public Texture2D white;
  186.     9:     public float time;
  187.    10:     float firstTime;
  188.    11:     Color col;
  189.    12  
  190.    13:     void Start ()
  191.    14:     {
  192.    15:         col = Color.black;
  193.    16:         if (!fadeIn)
  194.    17:         {
  195.    18:             col.a = 0f;
  196.    19:         }
  197.    20  
  198.    21:         firstTime = time;
  199.    22:     }
  200.    23:    
  201.    24:  void Update ()
  202.    25:     {
  203.    26:         time -= Time.deltaTime;
  204.    27  
  205.    28:         if (!fadeIn)
  206.    29:         {
  207.    30:             col.a = time / firstTime;
  208.    31:         }
  209.    32:         else
  210.    33:         {
  211.    34:             col.a = 1 - time / firstTime;
  212.    35:         }
  213.    36  
  214.    37  
  215.    38:         if (time < 0.01f && fadeIn)
  216.    39:         {
  217.    40:             Instantiate(prefab).GetComponent<fadeOutScript>().fadeIn = false;
  218.    41:         }
  219.    42  
  220.    43:         if (time < 0)
  221.    44:         {
  222.    45:             Destroy(gameObject);
  223.    46:         }
  224.    47:     }
  225.    48  
  226.    49:     void OnGUI()
  227.    50:     {
  228.    51:         if (!fadeIn || time < firstTime - 0.1f)
  229.    52:         {
  230.    53:             GUI.color = col;
  231.    54:             GUI.DrawTexture(new Rect(0, 0, Screen.width, Screen.height), white);
  232.    55:         }
  233.    56:     }
  234.    57: }
  235.    58  
  236.  
  237. effects\screenShake.cs:
  238.     1: using System.Collections;
  239.     2: using System.Collections.Generic;
  240.     3: using UnityEngine;
  241.     4  
  242.     5: public class screenShake : MonoBehaviour {
  243.     6:     Transform screen;
  244.     7:     float shakeLeft;
  245.     8:     float currentStrength;
  246.     9:     public float maxScreenshake;
  247.    10  
  248.    11:     Vector3 origin;
  249.    12:     void Start()
  250.    13:     {
  251.    14:         screen = Camera.main.transform;
  252.    15:     }
  253.    16  
  254.    17:     public void shake(float t, float s)
  255.    18:     {
  256.    19:         if (currentStrength < maxScreenshake)
  257.    20:         {
  258.    21:             shakeLeft += t;
  259.    22:             currentStrength /= 1.5f;
  260.    23:             currentStrength += s;
  261.    24:             origin = screen.position;
  262.    25:         }
  263.    26:     }
  264.    27  
  265.    28:     void FixedUpdate()
  266.    29:     {
  267.    30:         if (shakeLeft > 0)
  268.    31:         {
  269.    32:             screen.position = origin + (Vector3)new Vector2(Random.Range(-currentStrength, currentStrength), Random.Range(-currentStrength, currentStrength));
  270.    33:             shakeLeft -= Time.fixedDeltaTime;
  271.    34:         }
  272.    35:         else
  273.    36:         {
  274.    37:             screen.position = new Vector3(0, 0, screen.position.z);
  275.    38:             shakeLeft = 0;
  276.    39:         }
  277.    40:     }
  278.    41: }
  279.    42  
  280.  
  281. enemyDirectorScript.cs:
  282.     1: using System.Collections;
  283.     2: using System.Collections.Generic;
  284.     3: using UnityEngine;
  285.     4  
  286.     5: public class enemyDirectorScript : MonoBehaviour {
  287.     6:     public string[] possibleActions;
  288.     7:  
  289.     8:  void OnTriggerEnter2D (Collider2D col)
  290.     9:     {
  291.    10:      if (col.gameObject.tag == "enemy")
  292.    11:         {
  293.    12:             runnerEnemyScript runner = col.gameObject.GetComponent<runnerEnemyScript>();
  294.    13:                 runner.changeDirection(possibleActions);
  295.    14:            
  296.    15:         }
  297.    16:  }
  298.    17: }
  299.  
  300. enemySpawnerScript.cs:
  301.     1: using System.Collections;
  302.     2: using System.Collections.Generic;
  303.     3: using UnityEngine;
  304.     4  
  305.     5: public class enemySpawnerScript : MonoBehaviour
  306.     6: {
  307.     7:     public GameObject[] enemyTypes;
  308.     8:     public Transform[] spawnPoints;
  309.     9  
  310.    10:     public Vector2 runnerFrq;
  311.    11  
  312.    12:     float difficulty;
  313.    13:     float timeUntilRunner = 1f;
  314.    14  
  315.    15:  void Start ()
  316.    16:     {
  317.    17  
  318.    18:  }
  319.    19  
  320.    20:     void setRunnerTime()
  321.    21:     {
  322.    22:         timeUntilRunner = Random.Range(runnerFrq.x, runnerFrq.y) / Mathf.Sqrt(Mathf.Sqrt(difficulty));
  323.    23:     }
  324.    24:  
  325.    25:  void Update ()
  326.    26:     {
  327.    27:         difficulty += Time.deltaTime;
  328.    28  
  329.    29:         if (timeUntilRunner > 0)
  330.    30:         {
  331.    31:             timeUntilRunner -= Time.deltaTime;
  332.    32:         }
  333.    33:         else
  334.    34:         {
  335.    35:             spawnEnemy(0);
  336.    36:             setRunnerTime();
  337.    37:         }
  338.    38:  }
  339.    39  
  340.    40:     void spawnEnemy(int type)
  341.    41:     {
  342.    42:         Instantiate(enemyTypes[type], spawnPoints[Random.Range(0, 2)].position, transform.rotation);
  343.    43:     }
  344.    44: }
  345.    45  
  346.  
  347. gameManager.cs:
  348.     1: using System.Collections;
  349.     2: using System.Collections.Generic;
  350.     3: using UnityEngine;
  351.     4  
  352.     5: public class gameManager : MonoBehaviour {
  353.     6  
  354.     7:     public TextMesh scorecounter;
  355.     8:     int score = 0;
  356.     9:     public GameObject fade;
  357.    10:     float losetimer = -1;
  358.    11:     public GameObject yousaved;
  359.    12  
  360.    13:     void Update()
  361.    14:     {
  362.    15:         updateGame();
  363.    16:     }
  364.    17  
  365.    18:     //GAME
  366.    19:     void newGame()
  367.    20:     {
  368.    21:         score = 0;
  369.    22:     }
  370.    23:  
  371.    24:     public void getScore(int s)
  372.    25:     {
  373.    26:         score += s;
  374.    27:         scorecounter.text = score.ToString();
  375.    28:     }
  376.    29  
  377.    30:     public void lose()
  378.    31:     {
  379.    32:         fadeOutScript f = Instantiate(fade).GetComponent<fadeOutScript>();
  380.    33:         f.fadeIn = true;
  381.    34:         f.time = 1f;
  382.    35:         losetimer = 1f;
  383.    36:     }
  384.    37  
  385.    38:     void updateGame()
  386.    39:     {
  387.    40:         if (losetimer != -1)
  388.    41:         {
  389.    42:             losetimer -= Time.deltaTime;
  390.    43:             if (losetimer < 0)
  391.    44:             {
  392.    45:                 losetimer = -1;
  393.    46:                 GameObject s = Instantiate(yousaved);
  394.    47:                 s.GetComponent<savedThingScript>().savedThings = score;
  395.    48:                 DontDestroyOnLoad(s);
  396.    49:                 Application.LoadLevel("lose");
  397.    50:             }
  398.    51:         }
  399.    52:     }
  400.    53: }
  401.    54  
  402.  
  403. playerScript.cs:
  404.     1: using System.Collections;
  405.     2: using System.Collections.Generic;
  406.     3: using UnityEngine;
  407.     4: using UnityEngine.UI;
  408.     5  
  409.     6: public class playerScript : MonoBehaviour {
  410.     7:     bool dead = false;
  411.     8  
  412.     9:     Transform t;
  413.    10:     Rigidbody2D rb;
  414.    11:     Animator animate;
  415.    12:     SpriteRenderer sr;
  416.    13:     BoxCollider2D bc;
  417.    14  
  418.    15:     LayerMask ignoreSelf;
  419.    16  
  420.    17:     public float movespeed;
  421.    18:     public float accelerationBreaking;
  422.    19:     public float gravity;
  423.    20:     public float jumpHeight;
  424.    21:     public float wallslideMultiplier;
  425.    22  
  426.    23:     float horKey;
  427.    24:     [HideInInspector]
  428.    25:     public bool jumpKey;
  429.    26:     bool throwKey;
  430.    27  
  431.    28:     float currentGravity;
  432.    29:     float currentJump;
  433.    30  
  434.    31:     Vector2 move;
  435.    32:     public float movementMultiplier = 1;
  436.    33  
  437.    34:     bool floored;
  438.    35:     bool roofed;
  439.    36:     bool righted;
  440.    37:     bool lefted;
  441.    38:     bool walled;
  442.    39  
  443.    40:     bool lastFloored;
  444.    41:     bool lastRoofed;
  445.    42  
  446.    43:     float aimDir;
  447.    44:     public bool hasBoomerang;
  448.    45:     public GameObject boomerangPrefab;
  449.    46:     float boomerangCharge;
  450.    47  
  451.    48:     float justThrew;
  452.    49  
  453.    50:     public bool canJump;
  454.    51  
  455.    52:     AudioSource[] audio;
  456.    53  
  457.    54:     public GameObject deatheffect;
  458.    55  
  459.    56:     int health = 3;
  460.    57  
  461.    58:     public Sprite[] hearts;
  462.    59:     public Image[] containers;
  463.    60  
  464.    61:  void Start ()
  465.    62:     {
  466.    63:         QualitySettings.vSyncCount = 0;
  467.    64:         Application.targetFrameRate = 60;
  468.    65:         cache();
  469.    66:  }
  470.    67  
  471.    68:     void cache()
  472.    69:     {
  473.    70:         t = transform;
  474.    71:         rb = GetComponent<Rigidbody2D>();
  475.    72:         sr = GetComponent<SpriteRenderer>();
  476.    73:         animate = GetComponent<Animator>();
  477.    74:         bc = GetComponent<BoxCollider2D>();
  478.    75  
  479.    76:         audio = GetComponents<AudioSource>();
  480.    77:     }
  481.    78:  
  482.    79:  void Update ()
  483.    80:     {
  484.    81:         if (!dead)
  485.    82:         {
  486.    83:             getInput();
  487.    84:             hitHead();
  488.    85:             setGravity();
  489.    86:             setJump();
  490.    87:             setMove();
  491.    88:             checkThrowing();
  492.    89  
  493.    90:             animatePlayer();
  494.    91  
  495.    92:             if (t.position.y < -8.5f)
  496.    93:             {
  497.    94:                 die();
  498.    95:             }
  499.    96:         }
  500.    97:     }
  501.    98  
  502.    99:     void getInput ()
  503.   100:     {
  504.   101:         horKey = global.boolToFloat(Input.GetKey(KeyCode.RightArrow)) - global.boolToFloat(Input.GetKey(KeyCode.LeftArrow));
  505.   102:         jumpKey = Input.GetKeyDown(KeyCode.X);
  506.   103:         throwKey = Input.GetKey(KeyCode.C);
  507.   104  
  508.   105:         if (horKey != 0)
  509.   106:         {
  510.   107:             aimDir = horKey;
  511.   108:         }
  512.   109:     }
  513.   110  
  514.   111:     void setGroundedRoofed()
  515.   112:     {
  516.   113:         //floor
  517.   114:         RaycastHit2D[] floorHit = Physics2D.BoxCastAll(t.position, bc.size, 0, -Vector2.up);
  518.   115:         floored = false;
  519.   116:         foreach (RaycastHit2D ray in floorHit)
  520.   117:         {
  521.   118:             if (ray && ray.collider.tag == "solid" && ray.distance < 0.1f)
  522.   119:             {
  523.   120:                 floored = true;
  524.   121:             }
  525.   122:         }
  526.   123  
  527.   124:         if (floored != lastFloored && floored)
  528.   125:         {
  529.   126:             audio[4].Play();
  530.   127:         }
  531.   128:         lastFloored = floored;
  532.   129  
  533.   130:         //roof
  534.   131:         RaycastHit2D[] roofHit = Physics2D.BoxCastAll(t.position, bc.size, 0, Vector2.up);
  535.   132:         roofed = false;
  536.   133:         foreach (RaycastHit2D ray in roofHit)
  537.   134:         {
  538.   135:             if (ray && ray.collider.tag == "solid" && ray.distance < 0.1f)
  539.   136:             {
  540.   137:                 roofed = true;
  541.   138:             }
  542.   139:         }
  543.   140  
  544.   141:         if (roofed != lastRoofed && roofed)
  545.   142:         {
  546.   143:             audio[4].Play();
  547.   144:         }
  548.   145:         lastRoofed = roofed;
  549.   146  
  550.   147:         RaycastHit2D[] right = Physics2D.BoxCastAll(t.position, bc.size, 0, Vector2.right);
  551.   148:         righted = false;
  552.   149:         foreach (RaycastHit2D ray in right)
  553.   150:         {
  554.   151:             if (ray && ray.collider.tag == "solid" && ray.distance < 0.1f)
  555.   152:             {
  556.   153:                 righted = true;
  557.   154:             }
  558.   155:         }
  559.   156  
  560.   157:         RaycastHit2D[] left = Physics2D.BoxCastAll(t.position, bc.size, 0, Vector2.left);
  561.   158:         lefted = false;
  562.   159:         foreach (RaycastHit2D ray in left)
  563.   160:         {
  564.   161:             if (ray && ray.collider.tag == "solid" && ray.distance < 0.1f)
  565.   162:             {
  566.   163:                 lefted = true;
  567.   164:             }
  568.   165:         }
  569.   166:        
  570.   167:         walled = lefted || righted;
  571.   168:     }
  572.   169  
  573.   170:     void setGravity ()
  574.   171:     {
  575.   172:         if (!floored)
  576.   173:         {
  577.   174:             float curModGrav = gravity;
  578.   175:             if (walled && currentGravity > 0)
  579.   176:             {
  580.   177:                 curModGrav *= wallslideMultiplier;
  581.   178:             }
  582.   179:             currentGravity += curModGrav * Time.deltaTime * 60f;
  583.   180:         }
  584.   181:         else if (!roofed && currentGravity > 0)
  585.   182:         {
  586.   183:             currentGravity = 0;
  587.   184:         }
  588.   185:     }
  589.   186  
  590.   187:     void hitHead ()
  591.   188:     {
  592.   189:         if (roofed && !floored && currentGravity < 0)
  593.   190:         {
  594.   191:             currentGravity = 0.1f;
  595.   192:         }
  596.   193:     }
  597.   194  
  598.   195:     void setJump ()
  599.   196:     {
  600.   197:         if (jumpKey && floored && canJump)
  601.   198:         {
  602.   199:             audio[0].Play();
  603.   200:             currentGravity = -jumpHeight * 100;
  604.   201:         }
  605.   202:         canJump = true;
  606.   203:     }
  607.   204  
  608.   205:     void setMove ()
  609.   206:     {
  610.   207:         move.x = Mathf.Lerp(move.x, horKey*movespeed, Time.deltaTime * accelerationBreaking);
  611.   208:         move.y = -currentGravity*Time.deltaTime;
  612.   209:     }
  613.   210  
  614.   211:     void checkThrowing ()
  615.   212:     {
  616.   213:         if (justThrew > 0)
  617.   214:         {
  618.   215:             justThrew -= Time.deltaTime;
  619.   216:         }
  620.   217:         else
  621.   218:         {
  622.   219:             justThrew = 0;
  623.   220:         }
  624.   221  
  625.   222:         if (throwKey && hasBoomerang)
  626.   223:         {
  627.   224:             Time.timeScale = 0.2f;
  628.   225:             movementMultiplier = 0;
  629.   226:             currentGravity = 2;
  630.   227:             horKey = 0;
  631.   228:             chargeUpThrow();
  632.   229:         }
  633.   230:         else
  634.   231:         {
  635.   232:             if (boomerangCharge > 0)
  636.   233:             {
  637.   234:                 throwBoomerang();
  638.   235:             }
  639.   236:             Time.timeScale = 1f;
  640.   237:             movementMultiplier = 1;
  641.   238:         }
  642.   239:     }
  643.   240  
  644.   241:     void chargeUpThrow()
  645.   242:     {
  646.   243:         if (hasBoomerang)
  647.   244:         {
  648.   245:             boomerangCharge += Time.deltaTime;
  649.   246:             audio[2].Play();
  650.   247:             audio[2].pitch = 1f + boomerangCharge * 20;
  651.   248:             if (boomerangCharge > 0.10f)
  652.   249:             {
  653.   250:                 throwBoomerang();
  654.   251:             }
  655.   252:         }
  656.   253:     }
  657.   254  
  658.   255:     void throwBoomerang()
  659.   256:     {
  660.   257:         audio[1].Play();
  661.   258:         Camera.main.GetComponent<screenShake>().shake(0.1f, 0.1f);
  662.   259:         GameObject boomerang = Instantiate(boomerangPrefab, t.position, t.rotation);
  663.   260:         boomerangScript boomerangScr = boomerang.GetComponent<boomerangScript>();
  664.   261:         boomerangScr.direction = aimDir;
  665.   262:         boomerangScr.throwPow = boomerangCharge;
  666.   263:         boomerangCharge = 0f;
  667.   264:         hasBoomerang = false;
  668.   265:         justThrew = 0.1f;
  669.   266:     }
  670.   267  
  671.   268:     void FixedUpdate ()
  672.   269:     {
  673.   270:         setGroundedRoofed();
  674.   271:         setMove();
  675.   272:         movePlayer();
  676.   273:     }
  677.   274  
  678.   275:     void movePlayer()
  679.   276:     {
  680.   277:         rb.velocity = move * movementMultiplier;
  681.   278:     }
  682.   279  
  683.   280:     void OnTriggerEnter2D(Collider2D col)
  684.   281:     {
  685.   282:         if (col.tag == "enemy")
  686.   283:         {
  687.   284:             runnerEnemyScript runner = col.GetComponent<runnerEnemyScript>();
  688.   285:             if (runner)
  689.   286:             {
  690.   287:                 runner.die();
  691.   288:             }
  692.   289:             hurt();
  693.   290:         }
  694.   291:     }
  695.   292  
  696.   293:     void OnTriggerStay2D(Collider2D col)
  697.   294:     {
  698.   295:         if (col.gameObject.tag == "boomerang")
  699.   296:         {
  700.   297:             catchBoomerang(col.gameObject);
  701.   298:         }
  702.   299:     }
  703.   300  
  704.   301:     void catchBoomerang(GameObject boom)
  705.   302:     {
  706.   303:         if (!boom.GetComponent<boomerangScript>().movingTowards)
  707.   304:         {
  708.   305:             audio[3].Play();
  709.   306:             Destroy(boom);
  710.   307:             hasBoomerang = true;
  711.   308:         }
  712.   309:     }
  713.   310  
  714.   311:     void animatePlayer()
  715.   312:     {
  716.   313:         sr.flipX = (aimDir < 0);
  717.   314  
  718.   315:         if (justThrew > 0)
  719.   316:         {
  720.   317:             animate.Play("throw");
  721.   318:         }
  722.   319:         else if (boomerangCharge != 0)
  723.   320:         {
  724.   321:             animate.Play("charging");
  725.   322:         }
  726.   323:         else if (move.y != 0)
  727.   324:         {
  728.   325:             if (move.y > 0)
  729.   326:             {
  730.   327:                 animate.Play("jumping animation");
  731.   328:             }
  732.   329:             else
  733.   330:             {
  734.   331:                 animate.Play("fall animation");
  735.   332:             }
  736.   333:             sr.flipX = false;
  737.   334:         }
  738.   335:         else if (Mathf.Abs(move.x) > movespeed / 3)
  739.   336:         {
  740.   337:             animate.Play("running animation");
  741.   338:         }
  742.   339:         else
  743.   340:         {
  744.   341:             animate.Play("idle animation");
  745.   342:         }
  746.   343:     }
  747.   344  
  748.   345:     void hurt()
  749.   346:     {
  750.   347:         health -= 1;
  751.   348:         if (health <= 0)
  752.   349:         {
  753.   350:             die();
  754.   351:         }
  755.   352:         Camera.main.GetComponent<screenShake>().shake(0.2f, 0.5f);
  756.   353:         audio[5].Play();
  757.   354:         Time.timeScale = 1f;
  758.   355  
  759.   356:         updateHeartContainers();
  760.   357:     }
  761.   358  
  762.   359:     void die()
  763.   360:     {
  764.   361:         Camera.main.GetComponent<screenShake>().shake(0.2f, 0.5f);
  765.   362:         Time.timeScale = 1f;
  766.   363:         Instantiate(deatheffect, t.position, t.rotation);
  767.   364:         GetComponent<Renderer>().enabled = false;
  768.   365:         GameObject.Find("always").GetComponent<gameManager>().lose();
  769.   366:         dead = true;
  770.   367:     }
  771.   368  
  772.   369:     void updateHeartContainers()
  773.   370:     {
  774.   371:         foreach (Image c in containers)
  775.   372:         {
  776.   373:             c.sprite = hearts[1];
  777.   374:         }
  778.   375  
  779.   376:         for(int i = 0; i < health; i++)
  780.   377:         {
  781.   378:             containers[i].sprite = hearts[0];
  782.   379:         }
  783.   380:     }
  784.   381: }
  785.  
  786. portalScript.cs:
  787.     1: using System.Collections;
  788.     2: using System.Collections.Generic;
  789.     3: using UnityEngine;
  790.     4  
  791.     5: public class portalScript : MonoBehaviour {
  792.     6:     Transform t;
  793.     7:     public float basesize;
  794.     8:     public float offset;
  795.     9  
  796.    10:     float extrasize;
  797.    11  
  798.    12:  void Start ()
  799.    13:     {
  800.    14:         t = transform;
  801.    15:         offset = Random.Range(-offset, offset);     
  802.    16:  }
  803.    17:  
  804.    18:  void Update ()
  805.    19:     {
  806.    20:         t.localScale = new Vector3(basesize+Mathf.Cos(Time.time*3+offset)/10+extrasize, basesize+Mathf.Sin(Time.time*3+offset)/10+extrasize, 0);
  807.    21  
  808.    22:         extrasize = Mathf.Lerp(extrasize, 0, Time.deltaTime * 3);
  809.    23:  }
  810.    24  
  811.    25:     public void usePortal()
  812.    26:     {
  813.    27:         extrasize = 0.2f;
  814.    28:     }
  815.    29: }
  816.    30  
  817.  
  818. roomManager.cs:
  819.     1: using System.Collections;
  820.     2: using System.Collections.Generic;
  821.     3: using UnityEngine;
  822.     4  
  823.     5: public class roomManager : MonoBehaviour {
  824.     6:     public GameObject cover;
  825.     7:     public Transform rooms;
  826.     8:     GameObject activeRoom;
  827.     9:  
  828.    10:     void Start()
  829.    11:     {
  830.    12:         findActiveRoom();
  831.    13:     }
  832.    14  
  833.    15:     void findActiveRoom()
  834.    16:     {
  835.    17:         for (int i = 0; i < rooms.childCount; i++)
  836.    18:         {
  837.    19:             Transform room = rooms.GetChild(i);
  838.    20:             if (room.gameObject.activeSelf)
  839.    21:             {
  840.    22:                 activeRoom = room.gameObject;
  841.    23:             }
  842.    24:         }
  843.    25:     }
  844.    26  
  845.    27:     public void startRoomLoad(string roomName)
  846.    28:     {
  847.    29:         loadRoom(roomName);
  848.    30:     }
  849.    31  
  850.    32:  public void loadRoom (string roomName)
  851.    33:     {
  852.    34:         activeRoom.SetActive(false);
  853.    35:         activeRoom = rooms.FindChild(roomName).gameObject;
  854.    36:         activeRoom.SetActive(true);
  855.    37:  }
  856.    38: }
  857.    39  
  858.  
  859. runnerEnemyScript.cs:
  860.     1: using System.Collections;
  861.     2: using System.Collections.Generic;
  862.     3: using UnityEngine;
  863.     4  
  864.     5: public class runnerEnemyScript : MonoBehaviour {
  865.     6:     Transform t;
  866.     7:     Rigidbody2D rb;
  867.     8:     BoxCollider2D bc;
  868.     9  
  869.    10:     [HideInInspector]
  870.    11:     public float runningDirection;
  871.    12  
  872.    13:     //prefabs
  873.    14:     public GameObject explosionPrefab;
  874.    15  
  875.    16:     //stats
  876.    17:     public float runningSpeed;
  877.    18:     public float gravity;
  878.    19:     public float jump;
  879.    20  
  880.    21:     //vars
  881.    22:     float currentGravity;
  882.    23:     Vector2 move;
  883.    24:     bool waitingForJump;
  884.    25  
  885.    26:     float wantedHorMove;
  886.    27:     float horMove;
  887.    28  
  888.    29:     void Start ()
  889.    30:     {
  890.    31:         t = transform;
  891.    32:         rb = GetComponent<Rigidbody2D>();
  892.    33:         bc = GetComponent<BoxCollider2D>();
  893.    34  
  894.    35:         runningSpeed *= Random.Range(1f, 1.2f);
  895.    36:  }
  896.    37:  
  897.    38:  void Update ()
  898.    39:     {
  899.    40:         setGravity();
  900.    41:         setMove();
  901.    42:         checkDead();
  902.    43:         //turnOnHit();
  903.    44:  }
  904.    45  
  905.    46:     public void changeDirection(string[] possibleMove)
  906.    47:     {
  907.    48:         string toMove = possibleMove[Random.Range(0,possibleMove.Length)];
  908.    49  
  909.    50:         if (toMove == "left")
  910.    51:         {
  911.    52:             runningDirection = -1f;
  912.    53:         }
  913.    54:         else if (toMove == "right")
  914.    55:         {
  915.    56:             runningDirection = 1f;
  916.    57:         }
  917.    58:         else if (toMove == "jump right")
  918.    59:         {
  919.    60:             waitingForJump = true;
  920.    61:             runningDirection = 1f;
  921.    62:         }
  922.    63:         else if (toMove == "jump left")
  923.    64:         {
  924.    65:             waitingForJump = true;
  925.    66:             runningDirection = -1f;
  926.    67:         }
  927.    68:         else if (toMove == "")
  928.    69:         {
  929.    70:             runningDirection = 0;
  930.    71:             waitingForJump = false;
  931.    72:         }
  932.    73:     }
  933.    74  
  934.    75:     void FixedUpdate()
  935.    76:     {
  936.    77:         moveObject();
  937.    78:     }
  938.    79  
  939.    80:     void setGravity()
  940.    81:     {
  941.    82:         RaycastHit2D[] floorHit = Physics2D.BoxCastAll(t.position, bc.size, 0, -Vector2.up);
  942.    83:         bool floored = false;
  943.    84:         foreach (RaycastHit2D ray in floorHit)
  944.    85:         {
  945.    86:             if (ray && ray.collider.tag == "solid" && ray.distance < 0.06f)
  946.    87:             {
  947.    88:                 floored = true;
  948.    89:             }
  949.    90:         }
  950.    91  
  951.    92:         if (!floored)
  952.    93:         {
  953.    94:             currentGravity += Time.deltaTime * gravity;
  954.    95:         }
  955.    96:         else if (currentGravity > 0)
  956.    97:         {
  957.    98:             if (waitingForJump)
  958.    99:             {
  959.   100:                 currentGravity = -jump;
  960.   101:                 waitingForJump = false;
  961.   102:             }
  962.   103:             else
  963.   104:             {
  964.   105:                 currentGravity = 0;
  965.   106:             }
  966.   107:         }
  967.   108:     }
  968.   109  
  969.   110:     void turnOnHit()
  970.   111:     {
  971.   112:         if (runningDirection > 0)
  972.   113:         {
  973.   114:             RaycastHit2D[] rightHit = Physics2D.BoxCastAll(t.position, bc.size, 0, Vector2.right);
  974.   115:             foreach (RaycastHit2D ray in rightHit)
  975.   116:             {
  976.   117:                 if (ray && ray.collider.tag == "solid" && ray.distance < 0.1f)
  977.   118:                 {
  978.   119:                     runningDirection = -runningDirection;
  979.   120:                 }
  980.   121:             }
  981.   122:         }
  982.   123:         else
  983.   124:         {
  984.   125:             RaycastHit2D[] leftHit = Physics2D.BoxCastAll(t.position, bc.size * 0.9f, 0, Vector2.left);
  985.   126:             foreach (RaycastHit2D ray in leftHit)
  986.   127:             {
  987.   128:                 if (ray && ray.collider.tag == "solid" && ray.distance < 0.1f)
  988.   129:                 {
  989.   130:                     runningDirection = -runningDirection;
  990.   131:                 }
  991.   132:             }
  992.   133:         }
  993.   134:     }
  994.   135  
  995.   136:     void setMove()
  996.   137:     {
  997.   138:         wantedHorMove = runningDirection * runningSpeed;
  998.   139:         horMove = Mathf.Lerp(wantedHorMove, horMove, Time.deltaTime * 7f);
  999.   140:         move = new Vector2(horMove, -currentGravity);
  1000.   141:     }
  1001.   142  
  1002.   143:     void moveObject()
  1003.   144:     {
  1004.   145:         rb.velocity = move;
  1005.   146:     }
  1006.   147  
  1007.   148:     void OnTriggerEnter2D(Collider2D col)
  1008.   149:     {
  1009.   150:         if (col.tag == "boomerang")
  1010.   151:         {
  1011.   152:             if (!col.GetComponent<boomerangScript>().hasHitFloor)
  1012.   153:                 getHit();
  1013.   154:         }
  1014.   155:     }
  1015.   156  
  1016.   157:     void checkDead()
  1017.   158:     {
  1018.   159:         if (t.position.y < -8.5f)
  1019.   160:         {
  1020.   161:             die();
  1021.   162:         }
  1022.   163:     }
  1023.   164  
  1024.   165:     void getHit()
  1025.   166:     {
  1026.   167:         GameObject.Find("always").GetComponent<gameManager>().getScore(1);
  1027.   168:         die();
  1028.   169:     }
  1029.   170  
  1030.   171:     public void die()
  1031.   172:     {
  1032.   173:         Instantiate(explosionPrefab, t.position, t.rotation);
  1033.   174:         Destroy(gameObject);
  1034.   175:     }
  1035.   176: }
  1036.   177  
  1037.  
  1038. savedThingScript.cs:
  1039.     1: using System.Collections;
  1040.     2: using System.Collections.Generic;
  1041.     3: using UnityEngine;
  1042.     4  
  1043.     5: public class savedThingScript : MonoBehaviour {
  1044.     6:     public int savedThings;
  1045.     7  
  1046.     8:  void Update ()
  1047.     9:     {
  1048.    10:         if (Application.loadedLevelName == "lose")
  1049.    11:         {
  1050.    12:             GameObject.Find("you saved").GetComponent<TextMesh>().text = "You saved "+savedThings+" green things!";
  1051.    13:             Destroy(gameObject);
  1052.    14:         }
  1053.    15:  }
  1054.    16: }
  1055.    17  
  1056.  
  1057. stateManagerScript.cs:
  1058.     1: using System.Collections;
  1059.     2: using System.Collections.Generic;
  1060.     3: using UnityEngine;
  1061.     4  
  1062.     5: public class stateManagerScript : MonoBehaviour {
  1063.     6:     GameObject cur;
  1064.     7  
  1065.     8:     public GameObject menu;
  1066.     9:     public GameObject game;
  1067.    10  
  1068.    11:     void Start ()
  1069.    12:     {
  1070.    13:         setState("menu");
  1071.    14:  }
  1072.    15  
  1073.    16:     public void setState(string s)
  1074.    17:     {
  1075.    18:         print(s);
  1076.    19:         if (s == "game")
  1077.    20:         {
  1078.    21:             cur = Instantiate(game);
  1079.    22:         }
  1080.    23:         else if (s == "menu")
  1081.    24:         {
  1082.    25:             cur = Instantiate(menu);
  1083.    26:         }
  1084.    27:     }
  1085.    28:  
  1086.    29:  void Update ()
  1087.    30:     {
  1088.    31:     
  1089.    32:  }
  1090.    33: }
  1091.    34  
  1092.  
  1093. targetScript.cs:
  1094.     1: using System.Collections;
  1095.     2: using System.Collections.Generic;
  1096.     3: using UnityEngine;
  1097.     4  
  1098.     5: public class targetScript : MonoBehaviour {
  1099.     6:     public GameObject explosion;
  1100.     7:  void OnTriggerEnter2D (Collider2D col)
  1101.     8:     {
  1102.     9:      if (col.tag == "boomerang")
  1103.    10:         {
  1104.    11:             die();
  1105.    12:         }
  1106.    13:  }
  1107.    14  
  1108.    15:     void die()
  1109.    16:     {
  1110.    17:         Camera.main.GetComponent<screenShake>().shake(0.1f, 0.3f);
  1111.    18:         Transform e = Instantiate(explosion, transform.position, transform.rotation).transform;
  1112.    19:         e.parent = null;
  1113.    20:         Destroy(gameObject);
  1114.    21:     }
  1115.    22: }
  1116.    23  
  1117.  
  1118. terminalScript.cs:
  1119.     1: using System.Collections;
  1120.     2: using System.Collections.Generic;
  1121.     3: using UnityEngine;
  1122.     4  
  1123.     5: public class terminalScript : MonoBehaviour {
  1124.     6  
  1125.     7:     public GameObject screen;
  1126.     8:     public GameObject press;
  1127.     9:     public playerScript player;
  1128.    10  
  1129.    11:     bool hasBoom;
  1130.    12:     bool isInside;
  1131.    13:     bool hasPressed;
  1132.    14:     bool hasDialoged;
  1133.    15:     bool hasQuit;
  1134.    16  
  1135.    17:     [TextArea(3,5)]
  1136.    18:     public string[] screenSay;
  1137.    19  
  1138.    20:     float timeToScreenshake = -1;
  1139.    21  
  1140.    22:     void Start()
  1141.    23:     {
  1142.    24:         player = GameObject.Find("player").GetComponent<playerScript>();
  1143.    25:     }
  1144.    26  
  1145.    27:  void Update()
  1146.    28:     {
  1147.    29:         if (isInside && !hasPressed)
  1148.    30:         {
  1149.    31:             player.canJump = false;
  1150.    32:             if (player.jumpKey)
  1151.    33:             {
  1152.    34:                 pressed();
  1153.    35:             }
  1154.    36:         }
  1155.    37  
  1156.    38:         if (screen.GetComponent<textboxScript>().diagloging)
  1157.    39:         {
  1158.    40:             GameObject.Find("player").GetComponent<playerScript>().movementMultiplier = 0f;
  1159.    41:             hasDialoged = true;
  1160.    42:         }
  1161.    43:        
  1162.    44:         if (timeToScreenshake != -1)
  1163.    45:         {
  1164.    46:             timeToScreenshake -= Time.deltaTime;
  1165.    47:             if (timeToScreenshake < 0)
  1166.    48:             {
  1167.    49:                 Camera.main.GetComponent<screenShake>().shake(0.5f, 0.3f);
  1168.    50:                 GameObject.Find("always").GetComponent<roomManager>().startRoomLoad("room 2");
  1169.    51:                 timeToScreenshake = -1;
  1170.    52:             }
  1171.    53:         }
  1172.    54:      }
  1173.    55  
  1174.    56:     void pressed()
  1175.    57:     {
  1176.    58:         timeToScreenshake = 6f;
  1177.    59:         screen.GetComponent<textboxScript>().set(screenSay);
  1178.    60:         press.SetActive(false);
  1179.    61:         hasPressed = true;
  1180.    62:         player.canJump = true;
  1181.    63:     }
  1182.    64  
  1183.    65:  void OnTriggerStay2D (Collider2D col)
  1184.    66:     {
  1185.    67:         if (col.gameObject.tag == "player" && !hasPressed)
  1186.    68:         {
  1187.    69:             press.SetActive(true);
  1188.    70:             isInside = true;
  1189.    71:         }
  1190.    72:  }
  1191.    73  
  1192.    74:     void OnTriggerExit2D (Collider2D col)
  1193.    75:     {
  1194.    76:         if (col.gameObject.tag == "player")
  1195.    77:         {
  1196.    78:             press.SetActive(false);
  1197.    79:         }
  1198.    80:         isInside = false;
  1199.    81:     }
  1200.    82: }
  1201.    83  
  1202.  
  1203. wrapScript.cs:
  1204.     1: using System.Collections;
  1205.     2: using System.Collections.Generic;
  1206.     3: using UnityEngine;
  1207.     4  
  1208.     5: public class wrapScript : MonoBehaviour {
  1209.     6:     Transform t;
  1210.     7:     public bool cantWrapVer;
  1211.     8:  void Start ()
  1212.     9:     {
  1213.    10:         t = transform;
  1214.    11:     }
  1215.    12:  
  1216.    13:  void Update ()
  1217.    14:     {
  1218.    15:      if (t.position.x > 11.5)
  1219.    16:         {
  1220.    17:             t.position = new Vector3(-11.4f, t.position.y, t.position.z);
  1221.    18:             trigger();
  1222.    19:         }
  1223.    20:         else if (t.position.x < -12)
  1224.    21:         {
  1225.    22:             t.position = new Vector3(11.4f, t.position.y, t.position.z);
  1226.    23:             trigger();
  1227.    24:         }
  1228.    25  
  1229.    26:         if (!cantWrapVer)
  1230.    27:         {
  1231.    28:             if (t.position.y < -8.5f)
  1232.    29:             {
  1233.    30:                 t.position = new Vector3(t.position.x, 8.5f, t.position.z);
  1234.    31:             }
  1235.    32:         }
  1236.    33:  }
  1237.    34  
  1238.    35:     void trigger()
  1239.    36:     {
  1240.    37:         GameObject.Find("portal sound").GetComponent<AudioSource>().Play();
  1241.    38  
  1242.    39:         GameObject portalObj = GameObject.Find("right portal");
  1243.    40:         portalObj.GetComponent<portalScript>().usePortal();
  1244.    41:         portalScript[] portals = portalObj.GetComponentsInChildren<portalScript>();
  1245.    42:         foreach (portalScript p in portals)
  1246.    43:         {
  1247.    44:             p.usePortal();
  1248.    45:         }
  1249.    46  
  1250.    47:         portalObj = GameObject.Find("left portal");
  1251.    48:         portalObj.GetComponent<portalScript>().usePortal();
  1252.    49:         portals = portalObj.GetComponentsInChildren<portalScript>();
  1253.    50:         foreach (portalScript p in portals)
  1254.    51:         {
  1255.    52:             p.usePortal();
  1256.    53:         }
  1257.    54:     }
  1258.    55: }
  1259.    56  
  1260.  
  1261. global.cs:
  1262.     1: using UnityEngine;
  1263.     2: using System.Collections;
  1264.     3  
  1265.     4: public class global {
  1266.     5  
  1267.     6:     public static string alphabet = "abcdefghijklmnopqrstuvwxyz";
  1268.     7  
  1269.     8:     public static float boolToFloat(bool b)
  1270.     9:     {
  1271.    10:         if (b)
  1272.    11:         {
  1273.    12:             return 1f;
  1274.    13:         }
  1275.    14:         return 0f;
  1276.    15:     }
  1277.    16  
  1278.    17:     public static Vector2 angleToVector2(float angle)
  1279.    18:     {
  1280.    19:         return (Vector2)(Quaternion.Euler(0, 0, angle) * Vector2.right);
  1281.    20:     }
  1282.    21  
  1283.    22:     public static float vector2ToAngle(Vector2 v2End, Vector2 v2Start)
  1284.    23:     {
  1285.    24:         Vector2 v2 = v2End - v2Start;
  1286.    25:         return normalizeRotation(180f+Mathf.Atan2(v2.y, v2.x) * Mathf.Rad2Deg);
  1287.    26:     }
  1288.    27  
  1289.    28:     public static float normalizeRotation(float rotation)
  1290.    29:     {
  1291.    30:         if (rotation > 360f)
  1292.    31:         {
  1293.    32:             do
  1294.    33:             {
  1295.    34:                 rotation -= 360f;
  1296.    35:             } while (rotation >= 360f);
  1297.    36:         }
  1298.    37:         else if (rotation < 1f)
  1299.    38:         {
  1300.    39:             do
  1301.    40:             {
  1302.    41:                 rotation += 360f;
  1303.    42:             } while (rotation <= 0f);
  1304.    43:         }
  1305.    44:         return rotation;
  1306.    45:     }
  1307.    46  
  1308.    47:     public static bool isBetween(float a, float min, float max)
  1309.    48:     {
  1310.    49:         if ((a < max && a > min) || (a > max && a < min))
  1311.    50:         {
  1312.    51:             return true;
  1313.    52:         }
  1314.    53:         return false;
  1315.    54:     }
  1316.    55: }
  1317.    56  
  1318.  
  1319. cubeScript.cs:
  1320.     1: using UnityEngine;
  1321.     2: using System.Collections;
  1322.     3  
  1323.     4: public class cubeScript : MonoBehaviour {
  1324.     5  
  1325.     6:     Transform t;
  1326.     7:  float firstTimer = 1;
  1327.     8  
  1328.     9:     void Start ()
  1329.    10:     {
  1330.    11:      t = transform;
  1331.    12:  }
  1332.    13  
  1333.    14:  void Update ()
  1334.    15:     {
  1335.    16:      if (Time.time < 1)
  1336.    17:         {
  1337.    18:          firstTimer += Time.deltaTime * 2;
  1338.    19:          t.Translate (Vector3.down * 3 * Time.deltaTime * firstTimer);
  1339.    20:      }
  1340.    21:         else if (Time.time < 2)
  1341.    22:         {
  1342.    23:          t.rotation = Quaternion.Lerp (t.rotation, Quaternion.Euler (new Vector3 (45, 45, 0)), Time.deltaTime * 5);
  1343.    24:      }
  1344.    25:         else if (Time.time < 2.1)
  1345.    26:         {
  1346.    27:          t.rotation = Quaternion.Euler (new Vector3 (45, 45, 0));
  1347.    28:      }
  1348.    29:         else if (Time.time > 2.5)
  1349.    30:         {
  1350.    31:             Application.LoadLevel(1);
  1351.    32:         }
  1352.    33:  }
  1353.    34: }
  1354.  
  1355. flashScript.cs:
  1356.     1: using UnityEngine;
  1357.     2: using System.Collections;
  1358.     3  
  1359.     4: public class flashScript : MonoBehaviour {
  1360.     5:  Transform t;
  1361.     6:  float flashTimer = 0;
  1362.     7:  void Start () {
  1363.     8:      gameObject.GetComponent<Renderer> ().material.color = Color.white;
  1364.     9:  }
  1365.    10:  void Update () {
  1366.    11:      if (Time.time > 1.7f && Time.time < 1.85f) {
  1367.    12:          if (flashTimer < 0) {
  1368.    13:              if (gameObject.GetComponent<Renderer> ().material.color == Color.white) {
  1369.    14:                  gameObject.GetComponent<Renderer> ().material.color = Color.black;
  1370.    15:              } else {
  1371.    16:                  gameObject.GetComponent<Renderer> ().material.color = Color.white;
  1372.    17:              }
  1373.    18:              flashTimer = 0.005f;
  1374.    19:          }
  1375.    20:          flashTimer -= Time.deltaTime;
  1376.    21:      } else if (Time.time > 1.7f) {
  1377.    22:          gameObject.GetComponent<Renderer> ().material.color = Color.black;
  1378.    23:      }
  1379.    24:  }
  1380.    25: }
  1381.  
  1382. textboxScript.cs:
  1383.     1: using System.Collections;
  1384.     2: using System.Collections.Generic;
  1385.     3: using UnityEngine;
  1386.     4  
  1387.     5: public class textboxScript : MonoBehaviour
  1388.     6: {
  1389.     7  
  1390.     8:   //Variables:
  1391.     9  
  1392.    10:     //Cached components [var]
  1393.    11:     TextMesh text;
  1394.    12:     AudioSource sound;
  1395.    13  
  1396.    14:     //Stats [var]
  1397.    15:     public float timeBetweenCharacters;
  1398.    16:     public float toneNormalization;
  1399.    17  
  1400.    18:     //Current variables [var]
  1401.    19:     string[] textboxQueue;
  1402.    20:     string written;
  1403.    21:     int currentBox;
  1404.    22:     int currentCharacter;
  1405.    23:     float timeUntilNextCharacter;
  1406.    24  
  1407.    25:     public bool diagloging;
  1408.    26:     bool canWrite;
  1409.    27  
  1410.    28  
  1411.    29  
  1412.    30:     //Functions:
  1413.    31  
  1414.    32:     //Start [>]
  1415.    33:     void Start()
  1416.    34:     {
  1417.    35:         cache();
  1418.    36:         disableBox();
  1419.    37:     }
  1420.    38  
  1421.    39:     //Cache [>]
  1422.    40:     void cache()
  1423.    41:     {
  1424.    42:         text = GetComponent<TextMesh>();
  1425.    43:         sound = GetComponent<AudioSource>();
  1426.    44:     }
  1427.    45:  
  1428.    46:     //Set boxes [>>]
  1429.    47:     public void set(string[] newQueue)
  1430.    48:     {
  1431.    49:         textboxQueue = newQueue;
  1432.    50:         currentBox = -1;
  1433.    51  
  1434.    52:         diagloging = true;
  1435.    53:         canWrite = true;
  1436.    54:        
  1437.    55:         text.text = "";
  1438.    56  
  1439.    57:         startNewBox();
  1440.    58:     }
  1441.    59  
  1442.    60:     //Update [>]
  1443.    61:  void Update ()
  1444.    62:     {
  1445.    63:      if (diagloging)
  1446.    64:         {
  1447.    65:             writeBox();
  1448.    66:         }
  1449.    67:  }
  1450.    68  
  1451.    69:     //Start new box [>]
  1452.    70:     void startNewBox ()
  1453.    71:     {
  1454.    72:         currentCharacter = 0;
  1455.    73:         currentBox += 1;
  1456.    74:         written = "";
  1457.    75:         timeUntilNextCharacter = 0f;
  1458.    76  
  1459.    77:         if (currentBox >= textboxQueue.Length)
  1460.    78:         {
  1461.    79:             disableBox();
  1462.    80:         }
  1463.    81:     }
  1464.    82  
  1465.    83:     //Write current box [>]
  1466.    84:     void writeBox ()
  1467.    85:     {
  1468.    86:         if (canWrite)
  1469.    87:         {
  1470.    88:             if (timeUntilNextCharacter > 0f)
  1471.    89:             {
  1472.    90:                 timeUntilNextCharacter -= Time.deltaTime;
  1473.    91:             }
  1474.    92:             else if (currentCharacter < textboxQueue[currentBox].Length)
  1475.    93:             {
  1476.    94:                 writeLetter();
  1477.    95:             }
  1478.    96:             else
  1479.    97:             {
  1480.    98:                 startNewBox();
  1481.    99:             }
  1482.   100:         }
  1483.   101:     }
  1484.   102  
  1485.   103:     void writeLetter()
  1486.   104:     {
  1487.   105:         currentCharacter += 1;
  1488.   106  
  1489.   107:         string thisChar;
  1490.   108:         if (currentCharacter < textboxQueue[currentBox].Length)
  1491.   109:         {
  1492.   110:             thisChar = textboxQueue[currentBox].Substring(currentCharacter, 1);
  1493.   111:         }
  1494.   112:         else
  1495.   113:         {
  1496.   114:             thisChar = "";
  1497.   115:         }
  1498.   116  
  1499.   117:         written = textboxQueue[currentBox].Insert(currentCharacter, "<color=#ffffff00>");
  1500.   118:         written = written.Insert(written.Length, "</color>");
  1501.   119:         timeUntilNextCharacter = timeBetweenCharacters;
  1502.   120  
  1503.   121:         //play sound
  1504.   122:         int letterIndex = global.alphabet.IndexOf(thisChar);
  1505.   123:         if (letterIndex > -1)
  1506.   124:         {
  1507.   125:             sound.pitch = 1f + ((float)letterIndex - 13) / 26f / toneNormalization;
  1508.   126:             sound.Play();
  1509.   127:         }
  1510.   128  
  1511.   129:         updateBox();
  1512.   130:     }
  1513.   131  
  1514.   132:     void updateBox()
  1515.   133:     {
  1516.   134:         text.text = written;
  1517.   135:     }
  1518.   136  
  1519.   137:     //Disable box
  1520.   138:     void disableBox()
  1521.   139:     {
  1522.   140:         diagloging = false;
  1523.   141:         canWrite = false;
  1524.   142:     }
  1525.   143: }
  1526.   144  
  1527.  
  1528. globalControlScript.cs:
  1529.     1: using System.Collections;
  1530.     2: using System.Collections.Generic;
  1531.     3: using UnityEngine;
  1532.     4  
  1533.     5: public class globalControlScript : MonoBehaviour {
  1534.     6:     void Start ()
  1535.     7:     {
  1536.     8:         DontDestroyOnLoad(gameObject);
  1537.     9:     }
  1538.    10  
  1539.    11:  void Update ()
  1540.    12:     {
  1541.    13:      if (Input.GetKeyDown(KeyCode.Escape))
  1542.    14:         {
  1543.    15:             Application.Quit();
  1544.    16:         }
  1545.    17:  }
  1546.    18: }
  1547.    19  
  1548.  
  1549. menuScript.cs:
  1550.     1: using System.Collections;
  1551.     2: using System.Collections.Generic;
  1552.     3: using UnityEngine;
  1553.     4  
  1554.     5: public class menuScript : MonoBehaviour {
  1555.     6:     public GameObject fade;
  1556.     7:     float timer = -1;
  1557.     8  
  1558.     9:     public string toLoad;
  1559.    10:  
  1560.    11:  void Update ()
  1561.    12:     {
  1562.    13:      if (Input.GetKeyDown(KeyCode.X) && timer == -1)
  1563.    14:         {
  1564.    15:             Instantiate(fade);
  1565.    16:             timer = 1;
  1566.    17:         }
  1567.    18  
  1568.    19:         if (timer > 0)
  1569.    20:         {
  1570.    21:             timer -= Time.deltaTime;
  1571.    22:         }
  1572.    23:         else if (timer < 0 && timer > -1f)
  1573.    24:         {
  1574.    25:             Application.LoadLevel(toLoad);
  1575.    26:         }
  1576.    27:  }
  1577.    28: }
  1578.    29
Add Comment
Please, Sign In to add comment