Пример #1
0
    // Update is called once per frame
    void Update()
    {
        if (Input.GetKeyDown(KeyCode.Alpha1))
        {
            ChangeWeapon(0);
        }
        else if (Input.GetKeyDown(KeyCode.Alpha2))
        {
            ChangeWeapon(1);
        }
        else if (Input.GetKeyDown(KeyCode.Alpha3))
        {
            ChangeWeapon(2);
        }


        switch (state)
        {
        case WeaponSystemState.Default:

            if (Input.GetMouseButtonDown(0))
            {
                currentSelectedWeapon.HandleLMBDown();
            }
            else
            {
                if (Input.GetMouseButton(0))
                {
                    currentSelectedWeapon.HandleLMBHold();
                }
            }

            if (Input.GetKeyDown(KeyCode.R))
            {
                MissileWeapon mw = currentSelectedWeapon as MissileWeapon;
                if (mw != null)
                {
                    if (!mw.infiniteMagazine)
                    {
                        if (!mw.IsMagazineFull())
                        {
                            StartReload();
                        }
                    }
                }
            }

            break;

        case WeaponSystemState.Reloading:

            Debug.Log("Reloading");
            if (Time.time > reloadingEndTime)
            {
                EndReload();
            }

            break;
        }

        //point the weapon to aim correctly
        if (currentSelectedWeapon is MissileWeapon)
        {
            //raycast
            Ray        ray = rayCastCamera.ViewportPointToRay(new Vector3(0.5F, 0.5F, 0));
            RaycastHit hit;
            if (Physics.Raycast(ray, out hit))
            {
                //print("I'm looking at " + hit.transform.name);
                currentSelectedWeapon.transform.forward = hit.point - currentSelectedWeapon.transform.position;
            }
            else
            {
                currentSelectedWeapon.transform.forward = ray.direction;
            }
        }

        weaponHUD.UpdateHUD(currentSelectedWeapon);
    }