Browse Source

added confetti on hit + respawn

weapons
Joshua Reason 9 years ago
parent
commit
918efe6079
7 changed files with 113 additions and 0 deletions
  1. BIN
      playable/Assets/Confetti.prefab
  2. +4
    -0
      playable/Assets/Confetti.prefab.meta
  3. BIN
      playable/Assets/Lachlan_jump_work.unity
  4. +20
    -0
      playable/Assets/Scripts/PlayerControler.cs
  5. +59
    -0
      playable/Assets/Scripts/confettiController.cs
  6. +8
    -0
      playable/Assets/Scripts/confettiController.cs.meta
  7. +22
    -0
      playable/Assets/Scripts/player2_controls.cs

BIN
playable/Assets/Confetti.prefab View File


+ 4
- 0
playable/Assets/Confetti.prefab.meta View File

@ -0,0 +1,4 @@
fileFormatVersion: 2
guid: 2b7103b046272c1498dac632285c2739
NativeFormatImporter:
userData:

BIN
playable/Assets/Lachlan_jump_work.unity View File


+ 20
- 0
playable/Assets/Scripts/PlayerControler.cs View File

@ -17,6 +17,7 @@ public class PlayerControler : MonoBehaviour {
public GameObject bullet;
public GameObject heart;
bool canJump = true;
public GameObject newConfetti;
@ -34,6 +35,9 @@ public class PlayerControler : MonoBehaviour {
if (updateHealth)
displayHealth (health);
if (health == 0)
death();
if (Input.GetKey (KeyCode.UpArrow)){
if (canJump == true){
@ -73,6 +77,21 @@ public class PlayerControler : MonoBehaviour {
}
}
private void Confettishoot(Vector3 target,float size){
Debug.Log ("Creating Confetti");
target.y += 1.5f;
for (int i = 0; i <size; i++) {
Instantiate (newConfetti, target, transform.rotation);
}
}
private void death(){
Vector3 spawnPos = new Vector3 (Random.Range (-20.0f, 20.0f), 15.0f, 0);
health = 3;
transform.position = spawnPos;
}
void OnCollisionEnter2D(Collision2D col){
if (col.collider.tag == "ground")
canJump = true;
@ -80,6 +99,7 @@ public class PlayerControler : MonoBehaviour {
canJump = true;
if(transform.position.y>col.transform.position.y){
col.gameObject.GetComponent<player2_controls>().health --;
Confettishoot(col.gameObject.transform.position,200.0f);
//health --;
rigidbody2D.velocity = jumpVector;
canJump = false;

+ 59
- 0
playable/Assets/Scripts/confettiController.cs View File

@ -0,0 +1,59 @@
using UnityEngine;
using System.Collections;
public class confettiController : MonoBehaviour {
public float lifeTime = 0.5f;
public float speed = 5;
private float startTime;
private float startScale;
// Use this for initialization
void Start () {
float rand = Random.Range (0, 7);
int randColour = Mathf.FloorToInt (rand);
startTime = Time.time;
startScale = transform.localScale.x;
rigidbody.velocity = Random.onUnitSphere * speed;
switch (randColour) {
case 0:
renderer.material.color = Color.cyan;
break;
case 1:
renderer.material.color = Color.red;
break;
case 2:
renderer.material.color = Color.blue;
break;
case 3:
renderer.material.color = Color.green;
break;
case 4:
renderer.material.color = Color.yellow;
break;
case 5:
renderer.material.color = Color.magenta;
break;
default:
renderer.material.color = Color.black;
break;
}
}
// Update is called once per frame
void Update () {
float newScale = Mathf.Lerp(0, startScale, Time.deltaTime / lifeTime);
transform.localScale = new Vector3(startScale-newScale, startScale-newScale, startScale-newScale);
if (Time.time - startTime > lifeTime) {
Destroy (gameObject, 0.0f);
}
}
}

+ 8
- 0
playable/Assets/Scripts/confettiController.cs.meta View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: cf3e4ef8e9821b74d8758c2572c02c3f
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:

+ 22
- 0
playable/Assets/Scripts/player2_controls.cs View File

@ -18,6 +18,7 @@ public class player2_controls : MonoBehaviour {
public GameObject heart;
bool canJump = true;
public GameObject newConfetti;
@ -34,6 +35,9 @@ public class player2_controls : MonoBehaviour {
}
if (updateHealth)
displayHealth (health);
if (health == 0)
death();
if (Input.GetKey (KeyCode.W)){
if (canJump == true){
@ -73,12 +77,30 @@ public class player2_controls : MonoBehaviour {
}
}
private void Confettishoot(Vector3 target,float size){
Debug.Log ("Creating Confetti");
target.y += 1.5f;
for (int i = 0; i <size; i++) {
Instantiate (newConfetti, target, transform.rotation);
}
}
private void death(){
Vector3 spawnPos = new Vector3 (Random.Range (-20.0f, 20.0f), 15.0f, 0);
health = 3;
transform.position = spawnPos;
}
void OnCollisionEnter2D(Collision2D col){
if (col.collider.tag == "ground")
canJump = true;
else if (col.collider.tag == "Player") {
if(transform.position.y>col.transform.position.y){
col.gameObject.GetComponent<PlayerControler>().health --;
Confettishoot(col.gameObject.transform.position,200.0f);
//health --;
rigidbody2D.velocity = jumpVector;
canJump = false;

Loading…
Cancel
Save