Example #1
0
    // Update is called once per frame
    void Update()
    {
        DirUpd();
        AnimMotor.updateanim();

        MovAnimMotor();
        if (floor & !jumping)
        {
            if (caninput)
            {
                if (Input.GetKeyDown(KeyCode.Z))
                {
                    Jump.Play();
                    Invoke("S", 0.1f);
                    AnimMotor.frame   = 0;
                    AnimMotor.counter = 0;
                    shdow.Anim();
                    AnimMotor.updateanim();
                    rigid.AddForce(Vector3.up * forcejmp);
                    landing = false;
                    walking = false;
                    idle    = false;
                }
            }
        }
        Debug.DrawLine(new Vector3(this.transform.position.x, this.transform.position.y + 0.15f, this.transform.position.z), new Vector3(this.transform.position.x, 0f, this.transform.position.z), Color.red);
        if (Physics.Raycast(new Vector3(this.transform.position.x, this.transform.position.y + 0.15f, this.transform.position.z), Vector3.down, dist))
        {
            if (saltar)
            {
                saltar = false;

                if (moving)
                {
                    walking = true;
                    idle    = false;
                }
                else
                {
                    idle            = false;
                    walking         = false;
                    landing         = true;
                    AnimMotor.frame = 0;
                    Invoke("StopLand", 0.5f);
                }
            }
            floor = true;
        }
        else
        {
            floor   = false;
            idle    = false;
            walking = false;
        }

        if (Physics.Raycast(this.transform.position, Vector3.down, out hit))
        {
            if (shdow.zfloor != hit.collider.transform.position.y + 0.14f)
            {
                shdow.zfloor = hit.collider.transform.position.y + 0.14f;
            }
        }
        if (caninput)
        {
            if (Input.GetKey(KeyCode.RightArrow))
            {
                xx = 1;
            }
            if (Input.GetKey(KeyCode.LeftArrow))
            {
                xx = -1;
            }
            if (Input.GetKey(KeyCode.UpArrow))
            {
                yy = 1;
            }
            if (Input.GetKey(KeyCode.DownArrow))
            {
                yy = -1;
            }
            if (Input.GetKeyUp(KeyCode.LeftArrow) || Input.GetKeyUp(KeyCode.RightArrow))
            {
                xx = 0;
            }
            if (Input.GetKeyUp(KeyCode.UpArrow) || Input.GetKeyUp(KeyCode.DownArrow))
            {
                yy = 0;
            }
        }

        if (floor)
        {
            if (moving)
            {
                walking = true;
                idle    = false;
            }
            if (caninput)
            {
                if (Input.GetKeyDown(KeyCode.DownArrow) || Input.GetKeyDown(KeyCode.UpArrow) || Input.GetKeyDown(KeyCode.RightArrow) || Input.GetKeyDown(KeyCode.LeftArrow))
                {
                    AnimMotor.frame = 0;
                    walking         = true;
                    idle            = false;
                    moving          = true;
                    landing         = false;
                }
                if (Input.GetKeyUp(KeyCode.DownArrow))
                {
                    AnimMotor.animid = 13;
                    AnimMotor.frame  = 0;
                }
                if (Input.GetKeyUp(KeyCode.UpArrow))
                {
                    AnimMotor.animid = 9;
                    AnimMotor.frame  = 0;
                }
                if (Input.GetKeyUp(KeyCode.RightArrow))
                {
                    AnimMotor.animid = 11;
                    AnimMotor.frame  = 0;
                }
                if (Input.GetKeyUp(KeyCode.LeftArrow))
                {
                    AnimMotor.animid = 15;
                    AnimMotor.frame  = 0;
                }
                if (!Input.GetKey(KeyCode.DownArrow) && !Input.GetKey(KeyCode.LeftArrow) && !Input.GetKey(KeyCode.UpArrow) && !Input.GetKey(KeyCode.RightArrow))
                {
                    walking = false;
                    idle    = true;
                    moving  = false;
                }
            }
        }

        this.transform.Translate(-yy * MovSPD, 0f, xx * MovSPD);
        if (Input.GetKeyDown(KeyCode.C))
        {
            iv.Dbg_show();
        }
    }