Browse Source

Player has millisecond of invulnerability after getting hit.

added rest time between attacks
master
Joshua Reason 9 years ago
parent
commit
536df032a3
4 changed files with 28 additions and 2 deletions
  1. BIN
      playable/Assets/Lachlan_jump_work.unity
  2. +1
    -0
      playable/Assets/Scripts/PlayerControler.cs
  3. +24
    -1
      playable/Assets/Scripts/playerController.cs
  4. +3
    -1
      playable/Assets/stickController.cs

BIN
playable/Assets/Lachlan_jump_work.unity View File


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

@ -92,6 +92,7 @@ public class PlayerControler : MonoBehaviour {
Vector3 spawnPos = new Vector3 (Random.Range (-20.0f, 20.0f), 15.0f, 0);
health = 3;
transform.position = spawnPos;
rigidbody2D.velocity = Vector2.zero;
}
}

+ 24
- 1
playable/Assets/Scripts/playerController.cs View File

@ -18,6 +18,9 @@ public class playerController : MonoBehaviour {
public float health; //holds health
public int confettiOnHit; //amount of confetti created on hit
public Vector2 healthPos;
public float invulTime;
public float attackWait;
public bool isHit;
private float displayedHealth = 3; //currently displayed health
private bool updateHealth = true; //if the health bar needs updating
@ -25,6 +28,8 @@ public class playerController : MonoBehaviour {
private bool canJump = true; // if player can jump
private List<GameObject> hearts = new List<GameObject> (); //list which holds health sprites;
private bool isSpinning = false; //checks if player is spin attacking
private float lastHit;
private float lastAttack;
void Start(){
@ -42,6 +47,7 @@ public class playerController : MonoBehaviour {
displayHealth ();
death ();
applyPlayerDirection (Input.GetAxisRaw (HorizontalBtn));
damage ();
}
void FixedUpdate() {
@ -59,8 +65,10 @@ public class playerController : MonoBehaviour {
}//end if
if (Input.GetAxisRaw (StrongAttackBtn)==1) {
if (!isSpinning)
if (!isSpinning && (lastAttack+attackWait) < Time.time){
lastAttack = Time.time;
StartCoroutine (spinAttack (Vector3.down * 360, 0.2f));
}
}
@ -113,6 +121,7 @@ public class playerController : MonoBehaviour {
Vector3 spawnPos = new Vector3 (Random.Range (-20.0f, 20.0f), 15.0f, 0); //picks random position
health = 3; //resets life
transform.position = spawnPos; //changes position
rigidbody2D.velocity = Vector2.zero;
}//end if
}//end death
@ -126,6 +135,17 @@ public class playerController : MonoBehaviour {
}
}
private void damage (){
if (isHit) {
gameObject.GetComponent<PolygonCollider2D> ().enabled = false;
isHit = false;
lastHit = Time.time;
}
if (lastHit+invulTime < Time.time)
gameObject.GetComponent<PolygonCollider2D> ().enabled = true;
}
IEnumerator spinAttack(Vector3 byAngles, float inTime) {
isSpinning = true;
stick.isAttacking = true;
@ -144,6 +164,9 @@ public class playerController : MonoBehaviour {
isSpinning = false;
stick.isAttacking = false;
}
void OnCollisionEnter2D(Collision2D col){

+ 3
- 1
playable/Assets/stickController.cs View File

@ -38,9 +38,11 @@ public class stickController : MonoBehaviour {
if(transform.position.y>col.transform.position.y){
if (isAttacking){
col.gameObject.GetComponent<playerController>().health --;
col.gameObject.GetComponent<playerController>().isHit = true;
Confettishoot(col.gameObject.transform.position,col.gameObject.GetComponent<playerController>().confettiOnHit);
Vector2 velocity = col.rigidbody.velocity;
velocity.y = 22;
velocity.y = 20;
col.rigidbody.velocity = velocity;
}
}

Loading…
Cancel
Save