示例#1
0
    void OnTriggerStay2D(Collider2D col)
    {
        if (col.name == "MainChar")
        {
            col.attachedRigidbody.isKinematic = true;

            rigid = col.attachedRigidbody;
        }

        if (Input.GetButton("MoveUp") && col.name == "MainChar")
        {
            col.transform.Translate(TransformFormat.getTransVel(Vector3.up * 0.04f));
        }
        if (Input.GetButton("MoveDown") && col.name == "LadderCollider")
        {
            col.transform.parent.transform.Translate(TransformFormat.getTransVel(Vector3.down * 0.04f));
        }
    }
示例#2
0
    void Move()
    {
        if (Input.GetButton("MoveLeft"))
        {
            if (!isHit)
            {
                transform.Translate(TransformFormat.getTransVel(Vector3.left * speed));
                anim.SetBool("MoveLeft", true);
            }
            dir = Vector3.left;
        }
        if (Input.GetButton("MoveRight"))
        {
            if (!isHit)
            {
                transform.Translate(TransformFormat.getTransVel(Vector3.right * speed));
                anim.SetBool("MoveRight", true);
            }
            dir = Vector3.right;
        }
        if (Input.GetButton("MoveLeft") && Input.GetButton("MoveRight"))
        {
            anim.SetBool("MoveLeft", false);
            anim.SetBool("MoveRight", false);
        }

        if (Input.GetButtonUp("MoveLeft") || isHit)
        {
            anim.SetBool("MoveLeft", false);
            if (dir == Vector3.left)
            {
                anim.SetFloat("IdleAnim", 0f);
            }
        }

        if (Input.GetButtonUp("MoveRight") || isHit)
        {
            anim.SetBool("MoveRight", false);
            if (dir == Vector3.right)
            {
                anim.SetFloat("IdleAnim", 1f);
            }
        }
    }
示例#3
0
    public IEnumerator MoveLeft(float waitT)
    {
        orientation = 0;
        yield return(new WaitForSeconds(waitT));

        dir   = Vector3.left;
        isHit = false;

        while (!isHit)
        {
            transform.Translate(TransformFormat.getTransVel(Vector3.left * speed));
            anim.SetBool("MoveLeft", true);
            yield return(null);
        }

        if (isHit)
        {
            StopCoroutine("MoveLeft");
            anim.SetBool("MoveLeft", false);
            anim.SetFloat("IdleAnim", 0f);

            StartCoroutine("MoveRight", waitTimetoTurn);
        }
    }