IEnumerator FirstSwing() { swordAnim.Play("SwordAttack1"); yield return(new WaitForSeconds(0.15f)); // Activate kill barrier swordKillCollider.enabled = true; yield return(new WaitForSeconds(0.25f)); windowForSecondSwing = true; if (currentSwordState == swordState.FirstSwing) { yield return(new WaitForSeconds(0.15f)); // Deactive kill barrier swordKillCollider.enabled = false; yield return(new WaitForSeconds(0.15f)); windowForSecondSwing = false; yield return(new WaitForSeconds(0.15f)); yield return(new WaitForSeconds(0.75f)); windowForSecondSwing = false; currentSwordState = swordState.Idle; } //0.70 left }
IEnumerator Block() { swordAnim.Play("SwordBlock"); //yield return new WaitForSeconds(0.10f); // Activate block isBlocking = true; yield return(new WaitForSeconds(0.60f)); // Deactive block isBlocking = false; yield return(new WaitForSeconds(0.65f)); currentSwordState = swordState.Idle; // 1.25 overall }
void Update() { AttackOnEnemy(); //Increments and Decrements if (Input.GetKeyDown(upState)) { temp = Mathf.Clamp(((int)swState) - 1, 0, 2); switch (temp) { case 0: swState = swordState.top; break; case 1: swState = swordState.middle; break; case 2: swState = swordState.bottom; break; } Debug.Log($"new swState={(int)swState}"); } if (Input.GetKeyDown(downState)) { temp = Mathf.Clamp(((int)swState) + 1, 0, 2); switch (temp) { case 0: swState = swordState.top; break; case 1: swState = swordState.middle; break; case 2: swState = swordState.bottom; break; } Debug.Log($"new swState={(int)swState}"); } //Animations if (this.gameObject.GetComponent <CharacterControl>().horizontal > 0 || this.gameObject.GetComponent <CharacterControl>().horizontal < 0) { if (swState == swordState.top) { anim.SetBool("midWalk", false); anim.SetBool("lowWalk", false); anim.SetBool("highWalk", true); if (Input.GetKeyDown(Attack)) { anim.SetTrigger("highAttack"); } } if (swState == swordState.middle) { anim.SetBool("lowWalk", false); anim.SetBool("highWalk", false); anim.SetBool("midWalk", true); if (Input.GetKeyDown(Attack)) { anim.SetTrigger("middleAttack"); } } if (swState == swordState.bottom) { anim.SetBool("highWalk", false); anim.SetBool("midWalk", false); anim.SetBool("lowWalk", true); if (Input.GetKeyDown(Attack)) { anim.SetTrigger("lowAttack"); } } } }
void Update() { if (isDead == true) { //Debug.LogError("Player dead"); } Vector3 forward = transform.TransformDirection(Vector3.forward); Vector3 toOther = guard.transform.position - transform.position; float angle = Vector3.Dot(forward, toOther); if (Vector3.Dot(forward, toOther) > 0) { print("guard infront"); } RaycastHit hitInfo; if (Physics.Raycast(Camera.main.transform.position, transform.forward, out hitInfo, 2f, executeIgnoreLayers)) { //hitInfo.transform.root if (hitInfo.transform.tag == "Hitbox") { skullUi.SetActive(true); Debug.Log("hits gaurd"); } else { skullUi.SetActive(false); Debug.Log("not gaurd"); } } else { skullUi.SetActive(false); Debug.Log("nothing"); } if (Input.GetMouseButton(0)) { if (currentSwordState == swordState.Idle) { //swordAnim.enabled = false; //swordAnim.enabled = true; // start first swing windowForSecondSwing = false; currentSwordState = swordState.FirstSwing; StartCoroutine(FirstSwing()); } else if (currentSwordState == swordState.FirstSwing && windowForSecondSwing == true) { //swordAnim.enabled = false; //swordAnim.enabled = true; //start second swing currentSwordState = swordState.SecondSwing; windowForSecondSwing = false; swordKillCollider.enabled = false; StartCoroutine(SecondSwing()); } else { // player is already doing something } } if (Input.GetMouseButton(1)) { if (currentSwordState == swordState.Idle) { windowForSecondSwing = false; currentSwordState = swordState.Blocking; StartCoroutine(Block()); } } }