Пример #1
0
    private void Start()
    {
        for (int i = 0; i < transform.childCount; i++)
        {
            //添加每一把抢
            managerdGuns.Add(transform.GetChild(i).GetComponent <FPSGun>());
        }

        if (managerdGuns.Count > 0)
        {
            //当前先使用的是第一把抢
            currentGun = managerdGuns[index];
        }
    }
Пример #2
0
    private void Update()
    {
        //当前是否有一把枪
        if (!currentGun)
        {
            return;
        }

        if (Input.GetButtonDown("Fire"))
        {
            //让当前使用的枪开枪
            currentGun.Fire();
        }

        if (Input.GetButtonDown("Reload"))
        {
            //让当前使用的枪换弹
            currentGun.Reload();
        }

        //换枪
        if (Input.GetButtonDown("Switch"))
        {
            //当前枪支设置为非激活
            currentGun.gameObject.SetActive(false);
            //方法一:
            // if (++index < managerdGuns.Count)
            // {}
            // else
            // { index = 0; }
            //方法二:
            //计算新枪的换号
            index = ++index % managerdGuns.Count;
            //更新当前枪支
            currentGun = managerdGuns[index];
            //新枪
            currentGun.gameObject.SetActive(true);
        }
    }
Пример #3
0
    public override void OnStateEnter(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
    {
        FPSGun currentGun = animator.GetComponent<FPSGun>();

        if (fire)
        {
            //获取开火声音
            AudioClip fireClip = currentGun.fireClip;
            //播放
            AudioSource.PlayClipAtPoint(fireClip,animator.transform.position);
            //播放特效
            currentGun.PlayerFireEffect();
        }

        if (reload)
        {
            //获取换弹声音
            AudioClip reloadClip = currentGun.reloadClip;
            //播放
            AudioSource.PlayClipAtPoint(reloadClip,animator.transform.position);
        }
    }