Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class weaponSwitch : MonoBehaviour {
- public int selectedWeapon = 0;
- [Header("Weapon Audio Info")]
- public AudioClip soundDraw;
- public AudioClip soundPutaway;
- public AudioSource audioSource;
- public Camera mainCamera;
- public float normalFOV;
- // Use this for initialization
- void Start ()
- {
- SelectWeapon();
- }
- // Update is called once per frame
- void Update ()
- {
- int previousSelectedWeapon = selectedWeapon;
- if (Input.GetAxis("Mouse ScrollWheel") > 0f)
- {
- if (selectedWeapon >= transform.childCount - 1)
- selectedWeapon = 0;
- else
- selectedWeapon++;
- }
- if (Input.GetAxis("Mouse ScrollWheel") < 0f)
- {
- if (selectedWeapon <= 0)
- selectedWeapon = transform.childCount - 1;
- else
- selectedWeapon--;
- }
- if (Input.GetKeyDown(KeyCode.Alpha1))
- {
- selectedWeapon = 0;
- }
- if (Input.GetKeyDown(KeyCode.Alpha2)&& transform.childCount >=2)
- {
- selectedWeapon = 1;
- }
- if (Input.GetKeyDown(KeyCode.Alpha3) && transform.childCount >= 3)
- {
- selectedWeapon = 2;
- }
- if (Input.GetKeyDown(KeyCode.Alpha4) && transform.childCount >= 4)
- {
- selectedWeapon = 3;
- }
- if (previousSelectedWeapon != selectedWeapon)
- {
- SelectWeapon();
- }
- }
- void SelectWeapon()
- {
- int i = 0;
- foreach (Transform weapon in transform)
- {
- if (i == selectedWeapon)
- weapon.gameObject.SetActive(true);
- else
- weapon.gameObject.SetActive(false);
- i++;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement