Beispiel #1
0
    private void Update()
    {
        if (Time.timeScale > 0)
        {
            ammo = gunData.GetLoadedAmmo();
            //if the gun is an object, is active, and has ammo
            if (gun != null && gun.activeSelf && ammo > 0)
            {
                // create the position that the bullet hits, makes it random in relation to the area the player is aiming at
                forwardPos = (transform.forward * rayLength) + (transform.right * Random.Range(-0.5f, 0.5f)) + (transform.up * Random.Range(-0.5f, 0.5f));

                // draw the ray for where the bullet is going to go
                Debug.DrawRay(transform.position, forwardPos);

                // if the player is pressing the shoot button and can shoot
                if (Input.GetButtonDown("Fire1") && canShoot)
                {
                    StartCoroutine(wait());
                    canShoot = false;
                }

                // reload the gun with the r key
                if (Input.GetKeyDown(KeyCode.R) && ammo > 0 && ammo < gunData.GetMaxLoadedAmmo())
                {
                    StartCoroutine(LocalReload());
                }
            }
        }
    }
    void Update()
    {
        GameObject curWeapon     = weapons.GetComponent <WeaponManager>().GetWeapon();
        WeaponData curWeaponData = curWeapon.GetComponent <WeaponData>();

        //This is much more efficient than before
        switch (curWeapon.name)
        {
        default:
            text.SetText("Mike f****d up somewhere");
            break;

        case "EmptyHand":
            text.SetText("");
            break;

        case "Sword":
            text.SetText("");
            break;

        case "pistol":

            if (curWeaponData.GetReloading())
            {
                text.SetText("Reloading...");
            }
            else
            {
                text.SetText(curWeaponData.GetLoadedAmmo() + "/" + curWeaponData.GetMaxLoadedAmmo());
            }
            break;

        case "grenade":
            text.SetText(curWeaponData.GetLoadedAmmo() + "/" + curWeaponData.GetMaxLoadedAmmo());
            break;
        }
    }