diff --git a/playable/Assets/Lachlan_jump_work.unity b/playable/Assets/Lachlan_jump_work.unity index 0ba3246..b893a0b 100644 Binary files a/playable/Assets/Lachlan_jump_work.unity and b/playable/Assets/Lachlan_jump_work.unity differ diff --git a/playable/Assets/Scripts/PlayerControler.cs b/playable/Assets/Scripts/PlayerControler.cs index 4c7cf86..63d996f 100644 --- a/playable/Assets/Scripts/PlayerControler.cs +++ b/playable/Assets/Scripts/PlayerControler.cs @@ -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; } } diff --git a/playable/Assets/Scripts/playerController.cs b/playable/Assets/Scripts/playerController.cs index e560130..fe2aacd 100644 --- a/playable/Assets/Scripts/playerController.cs +++ b/playable/Assets/Scripts/playerController.cs @@ -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 hearts = new List (); //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 ().enabled = false; + isHit = false; + lastHit = Time.time; + } + if (lastHit+invulTime < Time.time) + gameObject.GetComponent ().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){ diff --git a/playable/Assets/stickController.cs b/playable/Assets/stickController.cs index d413aa0..9bcbabc 100644 --- a/playable/Assets/stickController.cs +++ b/playable/Assets/stickController.cs @@ -38,9 +38,11 @@ public class stickController : MonoBehaviour { if(transform.position.y>col.transform.position.y){ if (isAttacking){ col.gameObject.GetComponent().health --; + col.gameObject.GetComponent().isHit = true; Confettishoot(col.gameObject.transform.position,col.gameObject.GetComponent().confettiOnHit); + Vector2 velocity = col.rigidbody.velocity; - velocity.y = 22; + velocity.y = 20; col.rigidbody.velocity = velocity; } }