private void Update() { if (anim.GetBool("Won") || anim.GetCurrentAnimatorStateInfo(0).IsName("Win") || anim.GetCurrentAnimatorStateInfo(0).IsName("Die")) { return; } // Debug.Log(m_Character.m_Rigidbody2D.velocity.y); float distanceToLeft = GameObject.Find("/PlatformLeft").transform.position.x; distanceToLeft = distanceToLeft - (gameObject.transform.position.x + gameObject.GetComponent <CapsuleCollider2D>().size.x); float distanceToRight = GameObject.Find("/PlatformRight").transform.position.x; distanceToRight = distanceToRight - (gameObject.transform.position.x + gameObject.GetComponent <CapsuleCollider2D>().size.x); if ((distanceToLeft > -4.57 && m_Character.m_FacingRight) || (distanceToRight <= 10 && !m_Character.m_FacingRight)) { m_Character.nearWall = true; // gameObject.GetComponents<BoxCollider2D>()[1].isTrigger = false; gameObject.GetComponents <BoxCollider2D>()[1].offset = new Vector2(0f, gameObject.GetComponents <BoxCollider2D>()[1].offset.y); if (m_Character.m_Rigidbody2D.velocity.y > -21f && !m_Character.m_Grounded && ((distanceToLeft > -4.57 && !m_Character.m_FacingRight) || (distanceToRight <= 10 && m_Character.m_FacingRight))) { m_Character.m_Rigidbody2D.velocity = new Vector2(m_Character.m_Rigidbody2D.velocity.x, m_Character.m_Rigidbody2D.velocity.y - 0.5f); } } else { m_Character.nearWall = false; // gameObject.GetComponents<BoxCollider2D>()[1].isTrigger = true; gameObject.GetComponents <BoxCollider2D>()[1].offset = new Vector2(-0.1f, gameObject.GetComponents <BoxCollider2D>()[1].offset.y); } // if (!wait.active() && startedWait == true) { // m_Character.preventMovement = false; // startedWait = false; // isColliding = false; // } // Debug.Log(m_Character.m_Rigidbody2D.velocity.x); if (!moveActive.active()) { anim.speed = 1f; } if (!m_Jump) { if (gameObject == player1) { m_Jump = CrossPlatformInputManager.GetButtonDown("Jump"); } if (gameObject == player2) { m_Jump = CrossPlatformInputManager.GetButtonDown("Jump2"); } } if (m_Character.m_Grounded) { jumpActive = false; } else { jumpActive = true; } // if(lariatActive) // lariatTimer -= Time.deltaTime; //Subtract the time since last frame from the timer. // if (lariatTimer < 0) { // lariatTimer = 0; //If timer is less than 0, reset it to 0 as we don't want it to be negative // lariatActive = false; // } heavyActive = this.anim.GetCurrentAnimatorStateInfo(0).IsName("Heavy"); mediumActive = this.anim.GetCurrentAnimatorStateInfo(0).IsName("Medium"); lightActive = this.anim.GetCurrentAnimatorStateInfo(0).IsName("Light"); // Handle Inputs // Debug.Log(gameObject.GetComponent<PlayerJumpPush>().isColliding); if (!this.anim.GetCurrentAnimatorStateInfo(0).IsName("Stun") && !moveActive.active() && !this.anim.GetCurrentAnimatorStateInfo(0).IsName("Block") && !gameObject.GetComponent <PlayerJumpPush>().isColliding) { if (Input.GetButtonDown("Vonder_Lariat")) { if (stamina.getStamina() >= 45f && gameObject.GetComponent <PlatformerCharacter2D>().m_Grounded) { if (!lariatCooldown.active()) { LariatAttack(); lariatCooldown.startCooldown(1f); // lariatActive = true; // lariatTimer = lariatCooldown; moveActive.startCooldown(0.4f); } } } else if ((Input.GetButtonDown("Vonder_Light") && gameObject == player1) || (Input.GetButtonDown("Vonder_Light 2") && gameObject == player2) && !heavyActive && !mediumActive) { if (!lightCooldown.active()) { Light(); tripleJab.run(); if (tripleJab.notLast()) { lightCooldown.startCooldown(0.2f); lightCooldownAmount = 0.2f; moveActive.startCooldown(0.1f); } else { lightCooldown.startCooldown(0.8f); lightCooldownAmount = 0.8f; moveActive.startCooldown(0.3f); } } } else if ((Input.GetButtonDown("Vonder_Medium") && gameObject == player1) || (Input.GetButtonDown("Vonder_Medium 2") && gameObject == player2) && !heavyActive && !lightActive) { if (!mediumCooldown.active()) { Medium(); mediumCooldown.startCooldown(0.5f); moveActive.startCooldown(0.5f); } } else if (Input.GetButtonDown("Vonder_Heavy")) { if (!heavyCooldown.active()) { Heavy(); heavyCooldown.startCooldown(0.8f); moveActive.startCooldown(0.8f); } } } // Updates Cooldown UI cooldownUI = m_Character.cooldownUI; // Light cooldownUI.transform.GetChild(0).gameObject.transform.GetChild(0) .gameObject.transform.GetChild(0).GetComponent <SimpleHealthBar>().UpdateBar(lightCooldown.getCurrentTime(), lightCooldownAmount); // Medium cooldownUI.transform.GetChild(1).gameObject.transform.GetChild(0) .gameObject.transform.GetChild(0).GetComponent <SimpleHealthBar>().UpdateBar(mediumCooldown.getCurrentTime(), 0.5f); // Heavy cooldownUI.transform.GetChild(2).gameObject.transform.GetChild(0) .gameObject.transform.GetChild(0).GetComponent <SimpleHealthBar>().UpdateBar(heavyCooldown.getCurrentTime(), 0.8f); // Special cooldownUI.transform.GetChild(3).gameObject.transform.GetChild(0) .gameObject.transform.GetChild(0).GetComponent <SimpleHealthBar>().UpdateBar(lariatCooldown.getCurrentTime(), 1f); // Freeze constraints after doing basic moves // if(this.anim.GetCurrentAnimatorStateInfo(0).IsName("Light") || this.anim.GetCurrentAnimatorStateInfo(0).IsName("Medium") // || this.anim.GetCurrentAnimatorStateInfo(0).IsName("Heavy") || this.anim.GetCurrentAnimatorStateInfo(0).IsName("Lariat")) { // gameObject.GetComponent<Rigidbody2D>().constraints = RigidbodyConstraints2D.FreezePositionX | RigidbodyConstraints2D.FreezeRotation; // } // Freeze constraints after doing basic moves if (this.anim.GetCurrentAnimatorStateInfo(0).IsName("Light") || this.anim.GetCurrentAnimatorStateInfo(0).IsName("Medium") || this.anim.GetCurrentAnimatorStateInfo(0).IsName("Heavy") || this.anim.GetCurrentAnimatorStateInfo(0).IsName("Lariat")) { // disableMove = true; if (!this.anim.GetCurrentAnimatorStateInfo(0).IsName("Stun") && !gameObject.GetComponent <Damage>().knockbacking&& !gameObject.GetComponent <PlayerJumpPush>().isColliding) { gameObject.GetComponent <Rigidbody2D>().constraints = RigidbodyConstraints2D.FreezePositionX | RigidbodyConstraints2D.FreezeRotation; } } // else { // disableMove = false; // } // Debug.Log(gameObject.GetComponent<Rigidbody2D>().constraints); if (this.anim.GetCurrentAnimatorStateInfo(0).IsName("Stun")) { damageWait.cancel(); } }
private void Update() { if (anim.GetBool("Won") || anim.GetCurrentAnimatorStateInfo(0).IsName("Win") || anim.GetCurrentAnimatorStateInfo(0).IsName("Die")) { return; } float distanceToLeft = GameObject.Find("/PlatformLeft").transform.position.x; distanceToLeft = distanceToLeft - (gameObject.transform.position.x + gameObject.GetComponent <CapsuleCollider2D>().size.x); float distanceToRight = GameObject.Find("/PlatformRight").transform.position.x; distanceToRight = distanceToRight - (gameObject.transform.position.x + gameObject.GetComponent <CapsuleCollider2D>().size.x); if ((distanceToLeft > -4.57 && m_Character.m_FacingRight) || (distanceToRight <= 10 && !m_Character.m_FacingRight)) { m_Character.nearWall = true; // gameObject.GetComponents<BoxCollider2D>()[1].isTrigger = true; gameObject.GetComponents <BoxCollider2D>()[1].offset = new Vector2(0f, gameObject.GetComponents <BoxCollider2D>()[1].offset.y); if (m_Character.m_Rigidbody2D.velocity.y > -21f && !m_Character.m_Grounded && ((distanceToLeft > -4.57 && !m_Character.m_FacingRight) || (distanceToRight <= 10 && m_Character.m_FacingRight))) { m_Character.m_Rigidbody2D.velocity = new Vector2(m_Character.m_Rigidbody2D.velocity.x, m_Character.m_Rigidbody2D.velocity.y - 0.5f); } } else { m_Character.nearWall = false; // gameObject.GetComponents<BoxCollider2D>()[1].isTrigger = true; gameObject.GetComponents <BoxCollider2D>()[1].offset = new Vector2(-0.1f, gameObject.GetComponents <BoxCollider2D>()[1].offset.y); } // Debug.Log(distanceToRight); // if (!wait.active() && startedWait == true) { // m_Character.preventMovement = false; // startedWait = false; // isColliding = false; // } // Debug.Log(m_Character.m_Rigidbody2D.velocity.x); if (!moveActive.active()) { anim.speed = 1f; } if (!m_Jump) { if (gameObject == player1) { m_Jump = CrossPlatformInputManager.GetButtonDown("Jump"); } if (gameObject == player2) { m_Jump = CrossPlatformInputManager.GetButtonDown("Jump2"); } } if (!m_Dodge) { m_Dodge = CrossPlatformInputManager.GetButtonDown("Taylor_Dodge"); } if (m_Character.m_Grounded) { jumpActive = false; } else { jumpActive = true; } // Detect current active attack heavyActive = this.anim.GetCurrentAnimatorStateInfo(0).IsName("Heavy"); mediumActive = this.anim.GetCurrentAnimatorStateInfo(0).IsName("Medium"); lightActive = this.anim.GetCurrentAnimatorStateInfo(0).IsName("Light"); // Handle Inputs if (!this.anim.GetCurrentAnimatorStateInfo(0).IsName("Stun") && !moveActive.active() && !this.anim.GetCurrentAnimatorStateInfo(0).IsName("Block") && !gameObject.GetComponent <PlayerJumpPush>().isColliding) { if (((Input.GetButtonDown("Taylor_Fire") || Input.GetAxis("Axis 10") != 0) && gameObject == player1 || (Input.GetButtonDown("Taylor_Fire 2") || Input.GetAxis("Axis 10 2") != 0) && gameObject == player2) && !heavyActive) { if (stamina.getStamina() >= 20f) { if (!fireCooldown.active()) { Shoot(); stamina.startCountdown(1f); fireCooldown.startCooldown(0.5f); } } } else if ((Input.GetButtonDown("Taylor_Light") && gameObject == player1) || (Input.GetButtonDown("Taylor_Light 2") && gameObject == player2) && !heavyActive) { if (!lightCooldown.active()) { Light(); tripleJab.run(); if (tripleJab.notLast()) { lightCooldown.startCooldown(0.2f); lightCooldownAmount = 0.2f; } else { lightCooldown.startCooldown(0.8f); lightCooldownAmount = 0.8f; moveActive.startCooldown(0.45f); } } } else if ((Input.GetButtonDown("Taylor_Medium") && gameObject == player1) || (Input.GetButtonDown("Taylor_Medium 2") && gameObject == player2) && !heavyActive) { if (!mediumCooldown.active()) { Medium(); mediumCooldown.startCooldown(0.5f); moveActive.startCooldown(0.2f); } } else if ((Input.GetButtonDown("Taylor_Heavy") && gameObject == player1) || (Input.GetButtonDown("Taylor_Heavy 2") && gameObject == player2)) { if (!heavyCooldown.active()) { Heavy(); heavyCooldown.startCooldown(0.8f); moveActive.startCooldown(0.5f); } } } // Updates Cooldown UI cooldownUI = m_Character.cooldownUI; // Light cooldownUI.transform.GetChild(0).gameObject.transform.GetChild(0) .gameObject.transform.GetChild(0).GetComponent <SimpleHealthBar>().UpdateBar(lightCooldown.getCurrentTime(), lightCooldownAmount); // Medium cooldownUI.transform.GetChild(1).gameObject.transform.GetChild(0) .gameObject.transform.GetChild(0).GetComponent <SimpleHealthBar>().UpdateBar(mediumCooldown.getCurrentTime(), 0.5f); // Heavy cooldownUI.transform.GetChild(2).gameObject.transform.GetChild(0) .gameObject.transform.GetChild(0).GetComponent <SimpleHealthBar>().UpdateBar(heavyCooldown.getCurrentTime(), 0.8f); // Special cooldownUI.transform.GetChild(3).gameObject.transform.GetChild(0) .gameObject.transform.GetChild(0).GetComponent <SimpleHealthBar>().UpdateBar(fireCooldown.getCurrentTime(), 0.2f); // Freeze constraints after doing basic moves if (this.anim.GetCurrentAnimatorStateInfo(0).IsName("Light") || this.anim.GetCurrentAnimatorStateInfo(0).IsName("Medium") || this.anim.GetCurrentAnimatorStateInfo(0).IsName("Heavy") || this.anim.GetCurrentAnimatorStateInfo(0).IsName("Fire")) { if (!this.anim.GetCurrentAnimatorStateInfo(0).IsName("Stun") && !gameObject.GetComponent <Damage>().knockbacking&& !gameObject.GetComponent <PlayerJumpPush>().isColliding) { gameObject.GetComponent <Rigidbody2D>().constraints = RigidbodyConstraints2D.FreezePositionX | RigidbodyConstraints2D.FreezeRotation; } } if (this.anim.GetCurrentAnimatorStateInfo(0).IsName("Stun")) { damageWait.cancel(); } }