Exemplo n.º 1
0
    void Update()
    {
        updateRenderVisibility();

        if (!isLocalPlayer)
        {
            return;
        }

        //visibility
        if (!IsInvisible)
        {
            _timer += Time.deltaTime;
        }
        if (_timer > 2)
        {
            CmdSetInvisible(true);
            _timer = 0;
        }

        var x = Input.GetAxis("Horizontal") * Time.deltaTime * PlayerSpeed;
        var z = Input.GetAxis("Vertical") * Time.deltaTime * PlayerSpeed;

        if (WeaponToEquip != null)
        {
            EquipWeapon(WeaponToEquip);
            WeaponToEquip = null;
        }

        Plane playerPlane = new Plane(Vector3.up, transform.position);

        Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);

        float hitdist = 0.0f;

        if (playerPlane.Raycast(ray, out hitdist))
        {
            Vector3 targetPoint = ray.GetPoint(hitdist);

            Quaternion targetRotation = Quaternion.LookRotation(targetPoint - transform.position);

            transform.rotation = Quaternion.Slerp(transform.rotation, targetRotation, 30 * Time.deltaTime);
        }

        transform.Translate(x, 0, z, Space.World);

        if (Input.GetMouseButtonDown(0))
        {
            if (_equipedWeapon != null)
            {
                _equipedWeapon.ButtonDown();
            }
        }

        if (Input.GetMouseButtonUp(0))
        {
            if (_equipedWeapon != null)
            {
                _equipedWeapon.ButtonUp();
            }
        }
        if (_equipedWeapon != null)
        {
            _equipedWeapon.RunUpdate(Time.deltaTime);
        }
    }