Exemple #1
0
    // Update is called once per frame
    void Update()
    {
        if (Input.GetButtonDown("Horizontal") || Input.GetButtonDown("Vertical"))
        {
            ClientSend.CharacterMovement((int)CharacterStats.Walk);
        }
        else if (Input.GetButtonUp("Horizontal") || Input.GetButtonUp("Vertical"))
        {
            ClientSend.CharacterMovement((int)CharacterStats.Idle);
        }

        movement.x = Input.GetAxisRaw("Horizontal");
        movement.y = Input.GetAxisRaw("Vertical");
        ClientSend.AnimatorMovement(movement);


        // Press G to take out or put back weapon
        if (!gameObject.GetComponent <AstronautManager>().red)
        {
            if (!isUsingWeapon)
            {
                if (Input.GetKeyDown(KeyCode.G))
                {
                    ClientSend.PlayerUsingWeapon(true);
                    isUsingWeapon = true;
                }
            }
            else
            {
                if (Input.GetKeyDown(KeyCode.G))
                {
                    ClientSend.PlayerUsingWeapon(false);
                    isUsingWeapon = false;
                }
            }
        }

        if (isUsingWeapon)
        {
            Vector3 difference = Camera.main.ScreenToWorldPoint(Input.mousePosition) - transform.position;
            float   rotZ       = Mathf.Atan2(difference.y, difference.x) * Mathf.Rad2Deg;
            ClientSend.WeaponRotation(Quaternion.Euler(0f, 0f, rotZ + offset));

            if (timeBtwShots <= 0)
            {
                if (Input.GetMouseButton(0))
                {
                    ClientSend.PlayerShoot();
                    timeBtwShots = startTimeBtwShots;
                }
            }
            else
            {
                timeBtwShots -= Time.deltaTime;
            }
        }

        // Press B to drop bomb
        if (Input.GetKeyDown(KeyCode.B))
        {
            ClientSend.PlayerDropBomb();
        }
    }