Browse Source

-Added dash attack

-Menu pause
master
Joshua Reason 9 years ago
parent
commit
5ef6b8a966
5 changed files with 70 additions and 1 deletions
  1. BIN
      playable/Assets/Lachlan_jump_work.unity
  2. +4
    -0
      playable/Assets/Menu.cs
  3. +66
    -1
      playable/Assets/Scripts/playerController.cs
  4. BIN
      playable/ProjectSettings/InputManager.asset
  5. BIN
      playable/ProjectSettings/TagManager.asset

BIN
playable/Assets/Lachlan_jump_work.unity View File


+ 4
- 0
playable/Assets/Menu.cs View File

@ -34,6 +34,10 @@ public class Menu : MonoBehaviour {
start = !start;
menu = false;
}
if (start || menu)
Time.timeScale = 0;
else
Time.timeScale = 1;
}
void OnGUI ()

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

@ -7,6 +7,7 @@ public class playerController : MonoBehaviour {
public string HorizontalBtn; //holds string for horizontal input
public string VerticalBtn; //holds string for Vertical input
public string StrongAttackBtn;
public string DashAttackBtn;
public Animator animator; //Holds animator for Pinata
public GameObject heart; //Health sprites
@ -24,6 +25,9 @@ public class playerController : MonoBehaviour {
public float invulTime;
public float attackWait;
public bool isHit;
public float dashDistance;
public float dashTime;
public float dashWait;
private float displayedHealth = 3; //currently displayed health
private bool updateHealth = true; //if the health bar needs updating
@ -35,7 +39,10 @@ public class playerController : MonoBehaviour {
private float lastHit;
private float lastAttack;
private int score;
private bool isDashing =false;
private bool canDash = true;
private float lastDash;
private bool stopDash = false;
void Start(){
if (transform.rotation.y == 180)
@ -59,6 +66,7 @@ public class playerController : MonoBehaviour {
if (score >= 10) {
gameOverDisplay.enabled = true;
gameOverDisplay.text = ""+ gameObject.name + " Wins";
Time.timeScale = 0;
}
@ -86,6 +94,15 @@ public class playerController : MonoBehaviour {
}
}
if (Input.GetAxisRaw (DashAttackBtn) == 1) {
//Debug.Log ("dashbutton pressed");
if(!isDashing && canDash && Time.time - lastDash > dashWait){
lastDash = Time.time;
StartCoroutine (dashAttack (dashDistance,dashTime));
}
}
rigidbody2D.velocity = velocity; //apply inputs
@ -184,6 +201,49 @@ public class playerController : MonoBehaviour {
stick.isAttacking = false;
}
IEnumerator dashAttack (float dashDistance,float dashTime) {
float endPosition;
int dashDirection;
isDashing = true;
canDash = false;
stick.isAttacking = true;
Debug.Log ("" + gameObject.name + "Dashing");
rigidbody2D.gravityScale = 0;
Vector3 startPosition = transform.position;
Debug.Log ("rotation Y: " + transform.eulerAngles.y);
if (transform.eulerAngles.y >= 150)
dashDirection = -1;
else
dashDirection = 1;
endPosition = startPosition.x + (dashDirection * dashDistance);
Debug.Log ("Dash start: " + startPosition.x);
Debug.Log ("Dash Direction: " + (dashDirection ));
Debug.Log ("Dash end: " + endPosition);
for (float i = 0; i < 1; i += Time.deltaTime/dashTime) {
transform.position = new Vector3(dashDirection * Mathf.Lerp((dashDirection)*startPosition.x, (dashDirection)* endPosition, i), startPosition.y, startPosition.z);
if (stopDash)
break;
yield return null;
}
stopDash = false;
isDashing = false;
canDash = true;
stick.isAttacking = false;
Debug.Log ("" + gameObject.name + " finished Dashing");
rigidbody2D.gravityScale = 4;
}
@ -197,6 +257,11 @@ public class playerController : MonoBehaviour {
canJump = true;
canSpin = true;
}
if (col.collider.tag == "wall") {
stopDash = true;
}
}
void OnTriggerEnter2D(Collider2D trig)

BIN
playable/ProjectSettings/InputManager.asset View File


BIN
playable/ProjectSettings/TagManager.asset View File


Loading…
Cancel
Save