Exemple #1
0
 void OnTriggerEnter2D(Collider2D THIAC)
 {
     Debug.Log("we're in");
     if (THIAC.gameObject == playerFight)
     {
         bc.Attack();
         Debug.Log("puncha those buns");
     }
 }
    void Update()
    {
        Color color = Color.blue;

        if (m_player.transform.position.x > transform.position.x)
        {
            m_characterController.FacingDirection = EDirection.RIGHT;
        }
        else
        {
            m_characterController.FacingDirection = EDirection.LEFT;
        }

        if (m_characterController.FacingDirection == EDirection.LEFT && transform.rotation.y != 180f)
        {
            transform.rotation = Quaternion.Euler(new Vector3(0f, 180f, 0f));
        }
        else if (m_characterController.FacingDirection == EDirection.RIGHT && transform.rotation.y != 0f)
        {
            transform.rotation = Quaternion.Euler(new Vector3(0f, 0f, 0f));
        }

        float distance = Vector2.Distance(transform.position, m_player.transform.position);

        if (!m_combat.IsAttacking)
        {
            if (distance > m_safeDistance)
            {
                Vector2 direction = m_player.transform.position - transform.position;
                m_characterController.Direction = direction;
                color = Color.red;
            }
            else
            {
                m_combat.Attack();
                color = Color.green;
            }
        }
        else
        {
            float   direction    = m_characterController.FacingDirection == EDirection.LEFT ? 1f : -1f;
            Vector2 attackOrigin = new Vector2(transform.position.x + (direction * (m_sr.size.x / 2f)),
                                               transform.position.y + m_sr.size.y / 2f);
            VisualDebug.DrawCross(attackOrigin, 0.15f, Color.green);
            Vector2 boxOrigin = new Vector2(attackOrigin.x + (direction * (m_attackX / 2f)), attackOrigin.y);
            VisualDebug.DrawBox(boxOrigin, new Vector2(m_attackX, m_attackY), Color.cyan);
        }

        Debug.DrawLine(transform.position, m_player.transform.position, color);
    }
    void Update()
    {
        Direction = Vector2.zero;

        if (!m_isDashing)
        {
            if (Input.GetKey(m_upKey))
            {
                Direction += new Vector2(0f, 1f);
            }
            else if (Input.GetKey(m_downKey))
            {
                Direction += new Vector2(0f, -1f);
            }

            if (Input.GetKey(m_leftKey))
            {
                FacingDirection = EDirection.LEFT;
                Direction      += new Vector2(-1f, 0f);
            }
            else if (Input.GetKey(m_rightKey))
            {
                FacingDirection = EDirection.RIGHT;
                Direction      += new Vector2(1f, 0f);
            }

            m_animator.SetFloat("hSpeed", Mathf.Abs(Direction.x));
            m_animator.SetFloat("vSpeed", Mathf.Abs(Direction.y));
        }

        if (Input.GetKeyDown(m_jumpKey))
        {
            m_jump = true;
            m_animator.SetBool("jump", true);
        }

        if (Input.GetKeyDown(m_attackKey))
        {
            Combat.Attack();
        }

        if (FacingDirection == EDirection.LEFT && transform.rotation.y != 180f)
        {
            transform.rotation = Quaternion.Euler(new Vector3(0f, 180f, 0f));
        }
        else if (FacingDirection == EDirection.RIGHT && transform.rotation.y != 0f)
        {
            transform.rotation = Quaternion.Euler(new Vector3(0f, 0f, 0f));
        }

        if (Input.GetKey(m_dashKey) && !m_isDashing && (Time.time >= m_lastDash + m_dashCooldown))
        {
            m_lastDash  = Time.time;
            m_isDashing = true;
        }

        if (m_debug)
        {
            Debug.DrawRay(transform.position, transform.right * 5f, Color.blue);
        }
    }