Ejemplo n.º 1
0
    void FixedUpdate()
    {
        cam = GameObject.Find("Main Camera").GetComponent <Camera>();

        if (health <= 0)
        {
            GameObject.Find("UICanvas").GetComponent <UI>().changeDialogue("You have died. Restarting in 3...");
            Tube.Restart();
            GameObject.Find("PC").transform.position = startPos;
        }

        if (exp >= 200)
        {
            LevelUp();
        }

        Vector3 dir = cam.ScreenToWorldPoint(Input.mousePosition) - _Blade.transform.position;

        dir.Normalize();

        if (cam.ScreenToWorldPoint(Input.mousePosition).x > transform.position.x + 0.2f)
        {
            mirror = false;
        }
        if (cam.ScreenToWorldPoint(Input.mousePosition).x < transform.position.x - 0.2f)
        {
            mirror = true;
        }

        if (!mirror)
        {
            rot = Mathf.Atan2(dir.y, dir.x) * Mathf.Rad2Deg;
            transform.localScale      = new Vector3(_startScale, _startScale, 1);
            _Blade.transform.rotation = Quaternion.AngleAxis(rot, Vector3.forward);
        }
        if (mirror)
        {
            rot = Mathf.Atan2(-dir.y, -dir.x) * Mathf.Rad2Deg;
            transform.localScale      = new Vector3(-_startScale, _startScale, 1);
            _Blade.transform.rotation = Quaternion.AngleAxis(rot, Vector3.forward);
        }

        if (_inputAxis.x != 0)
        {
            rig.velocity = new Vector2(_inputAxis.x * WalkSpeed * Time.deltaTime, rig.velocity.y);

            if (_canWalk)
            {
                _Legs.clip = _walk;
                _Legs.Play();
            }
        }
        else
        {
            rig.velocity = new Vector2(0, rig.velocity.y);
        }

        if (_isJump)
        {
            rig.AddForce(new Vector2(0, JumpForce));
            _Legs.clip = _jump;
            _Legs.Play();
            _canJump = false;
            _isJump  = false;
        }
    }
Ejemplo n.º 2
0
 void RestartOnClick()
 {
     Tube.Restart();
 }