public void CollideWithEnemy(GameObject other) { //Debug.Log(other.name + " hit in " + m_currentAttackType); //Check if its an enemy if (other.layer == 9) { EnemyController enem = other.GetComponent <EnemyController>(); if (m_currentAttackType == CollisionType.Strike) { enem.DealDamage(m_damageStrike); //strike knocks the enemy back away from you Vector2 direction = (other.transform.position - transform.position).normalized; enem.ApplyKnockback(direction * m_knockbackStrikeForce, m_knockbackStrikeDuration); } else { enem.DealDamage(m_damageSweep); //Sweep pushes the enemy forward Vector2 direction = -transform.right; enem.ApplyKnockback(direction * m_knockbackSweepForce, m_knockbackSweepDuration); } } //If its a parts pile else if (other.layer == 10) { PartsPile pile = other.GetComponent <PartsPile>(); //Parts piles are only affected by sweeps if (m_currentAttackType == CollisionType.Sweep) { Vector2 direction = -transform.right; pile.HitPile(direction * m_knockbackPileForce, m_knockbackPileDuration); } } }
private void FixedUpdate() { //If the pile is still set, but is disabled //Basically a saftey mechanism for when OnTriggerExit doesn't work if (m_currentPile != null && (!m_currentPile.gameObject.activeInHierarchy || m_currentPile.m_currentStackAmount == 3)) { m_movementPartSlowdownIndex = 0; m_currentPile = null; } //Get the user's input and add it to the velocity Vector3 inputDir = Vector3.zero; inputDir.x = Input.GetAxis("Horizontal"); inputDir.y = Input.GetAxis("Vertical"); if (inputDir.sqrMagnitude > 1) { inputDir = inputDir.normalized; } if (inputDir.sqrMagnitude != 0) { float angle = Mathf.Atan2(inputDir.y, inputDir.x) * Mathf.Rad2Deg; Quaternion rot = Quaternion.Euler(0, 0, angle); //Quaternion.AngleAxis(angle, Vector3.forward); transform.GetChild(0).rotation = rot; } transform.position += inputDir * m_movementForce * m_movementModifiers[m_movementPartSlowdownIndex] * Time.deltaTime; }
private void OnCollisionEnter2D(Collision2D collision) { //Check if collided with a pile if (collision.gameObject.layer == 10) { //If so, make sure the other pile didn't already absorb this pile if (gameObject.activeInHierarchy) { PartsPile other = collision.gameObject.GetComponent <PartsPile>(); //If we are moving and the other pile isn't, then do nothing and let it absorb this pile if (!(m_isInKnockback && !other.m_isInKnockback)) { //if the piles can fit if (m_currentStackAmount + other.m_currentStackAmount <= m_maxStackAmount) { collision.gameObject.SetActive(false); m_currentStackAmount += other.m_currentStackAmount; m_sprite.sprite = m_stackVisuals[m_currentStackAmount - 1]; if (m_currentStackAmount == m_maxStackAmount) { transform.GetChild(0).GetComponent <Collider2D>().isTrigger = false; } } } } } }
private void OnTriggerEnter2D(Collider2D collision) { if (collision.gameObject.layer == 11) { PartsPile pile = collision.transform.parent.GetComponent <PartsPile>(); m_movementPartSlowdownIndex = pile.m_currentStackAmount; m_currentPile = pile; } }
private void OnTriggerEnter2D(Collider2D collision) { if (collision.gameObject.layer == 10 && m_isOpen) { m_particle.Play(); SFXManager.i.Burn(); PartsPile pile = collision.gameObject.GetComponent <PartsPile>(); pile.gameObject.SetActive(false); GameController.i.AddScore(m_scoreAmounts[pile.m_currentStackAmount - 1]); StartCoroutine(CloseForTime()); } }