Пример #1
0
    private void OnTriggerStay2D(Collider2D other)
    {
        float v = Input.GetAxisRaw("P" + player + "_Vertical");

        RaycastHit2D hit  = Physics2D.Raycast(transform.position + Vector3.down * 1f, Vector2.down, groudCheckDistance, 1 << LayerMask.NameToLayer("Default"));
        RaycastHit2D hit2 = Physics2D.Raycast(transform.position + Vector3.up * 1f, Vector2.up, .3f, 1 << LayerMask.NameToLayer("Ladder"));

        if (other.gameObject.layer == 9 && hit2.collider != null && (hit.collider != null && v > 0 ||
                                                                     hit.collider == null) && v != 0 && rb.velocity.y <= 0)
        {
            //ENABLE LADDER
            checkGround = false;
            offGround   = OffGroundState.Ladder;
        }

        if (other.transform.name == "Door")
        {
            if (other.GetComponent <Animator>().GetCurrentAnimatorStateInfo(0).IsName("Opened"))
            {
                if (other.transform.name != "LinkedDoor")
                {
                    StartCoroutine(CS_GameManager.instance.EndLevel());
                    enableMovements = false;
                }
            }
            else if (Input.GetButtonDown("P" + player + "_Interact"))
            {
                CS_GameManager.instance.UpdateEvent();
            }
        }
    }
Пример #2
0
 private void OnTriggerExit2D(Collider2D other)
 {
     if (other.gameObject.layer == 9)
     {
         //DISABLE LADDER
         checkGround     = true;
         rb.gravityScale = 3;
         anim.SetBool("Climbing", false);
         offGround = OffGroundState.Airborne;
     }
 }
Пример #3
0
    // Use this for initialization
    void Start()
    {
        anim      = GetComponent <Animator>();
        rb        = GetComponent <Rigidbody2D>();
        audSource = GetComponent <AudioSource>();

        offGround = OffGroundState.Airborne;

        cs_Canvas.m_Character = this;
        this.enabled          = false;
    }
Пример #4
0
    void OnLadder()
    {
        float h    = Input.GetAxisRaw("P" + player + "_Horizontal");
        float v    = Input.GetAxisRaw("P" + player + "_Vertical");
        bool  jump = Input.GetButtonDown("P" + player + "_Jump");

        if (!anim.GetCurrentAnimatorStateInfo(0).IsName("Ladder"))
        {
            anim.SetBool("Climbing", true);
            anim.SetTrigger("EnterLadder");
        }

        Debug.DrawRay(transform.position + Vector3.up * 1f, Vector2.up * .3f);
        RaycastHit2D hit2 = Physics2D.Raycast(transform.position + Vector3.up * 1f, Vector2.up, .3f, 1 << LayerMask.NameToLayer("Ladder"));

        anim.SetFloat("Up", v);
        if (hit2.collider == null)
        {
            if (v < 0)
            {
                rb.velocity = new Vector2(h / 2 * moveSpeed, v * moveSpeed);
            }
            else
            {
                rb.velocity = new Vector2(h / 2 * moveSpeed, Mathf.Lerp(rb.velocity.y, 0, 10 * Time.deltaTime));
                anim.SetFloat("Up", 0);
            }
        }
        else
        {
            rb.velocity = new Vector2(h / 2 * moveSpeed, v * moveSpeed);
        }

        Debug.DrawRay(transform.position + Vector3.down * 1f, Vector2.down * groudCheckDistance);
        //DISABLE LADDER
        RaycastHit2D hit = Physics2D.Raycast(transform.position + Vector3.down * 1f, Vector2.down, groudCheckDistance, 1 << LayerMask.NameToLayer("Default"));

        if (hit.collider != null && !hit.collider.isTrigger && v < 0)
        {
            onGround           = true;
            checkGround        = true;
            groudCheckDistance = stdGCD;
            anim.SetBool("Climbing", false);
            offGround = OffGroundState.Airborne;
        }

        if (jump)
        {
            offGround = OffGroundState.Airborne;
            Jump();
        }
    }