// Start is called before the first frame update
 void Start()
 {
     ammoScript         = GetComponent <ReloadScript>();
     transform.position = initialPos.position;
     camera             = Camera.main;
 }
Beispiel #2
0
 // Update is called once per frame
 void Start()
 {
     ammoScript = GetComponent <ReloadScript>();
 }
    // Update is called once per frame
    void Update()
    {
        int          previousSelectedWeapon = selectedWeapon;
        ReloadScript ammoScript             = GetComponentInChildren <ReloadScript>();

        weaponScript = GetComponentInChildren <UniversalWeaponScript>();
        animator     = gameObject.GetComponent <Animator>();

        if (ammoScript != null)
        {
            if (ammoScript.reloading == false)
            {
                canChange = true;
            }
            else
            {
                canChange = false;
            }
        }


        if (weaponScript != null)
        {
            if (weaponScript.animator.GetCurrentAnimatorStateInfo(0).IsTag("Idle"))
            {
                canChange = true;
            }
            else
            {
                canChange = false;
            }
        }

        else
        {
            if (ammoScript == null)
            {
                canChange = true;
            }
        }

        if (Input.GetAxis("Mouse ScrollWheel") > 0f & (canChange))
        {
            if (selectedWeapon >= transform.childCount - 1)
            {
                selectedWeapon = 0;
            }
            else
            {
                selectedWeapon++;
            }
        }
        if (Input.GetAxis("Mouse ScrollWheel") < 0f & (canChange))
        {
            if (selectedWeapon <= 0)
            {
                selectedWeapon = transform.childCount - 1;
            }
            else
            {
                selectedWeapon--;
            }
        }
        if (previousSelectedWeapon != selectedWeapon)
        {
            SelectWeapon();
        }
        animator.SetBool("RunAndGun", false);

        if (animator.GetBool("Running") && weaponScript != null)
        {
            if (weaponScript.animator.GetCurrentAnimatorStateInfo(0).IsTag("Shoot"))
            {
                animator.SetBool("RunAndGun", true);
            }
        }
    }