资源简介

Unity工具C#语言制作的经典游戏换枪效果,缓存池实例化子弹,带所有资源(武器,代码等导入unity直接可用)

资源截图

代码片段和文件信息

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class ChangeArms : MonoBehaviour {

    public Gameobject[] weapons;                // 武器数组
    public int startingWeaponIndex = 0;         // 武器初始索引
    private int weaponIndex;                    // 武器索引


    // Use this for initialization
    void Start()
    {
        // 确保启动主武器是由用户在启动武器索引中选择的
        weaponIndex = startingWeaponIndex;
        SetActiveWeapon(weaponIndex);
    }

    // Update is called once per frame
    void Update()
    {
        // 允许用户立即切换到任何武器
        if (Input.GetButtonDown(“Weapon 1“))
            SetActiveWeapon(0);
        if (Input.GetButtonDown(“Weapon 2“))
            SetActiveWeapon(1);
        if (Input.GetButtonDown(“Weapon 3“))
            SetActiveWeapon(2);
        if (Input.GetButtonDown(“Weapon 4“))
            SetActiveWeapon(3);
        if (Input.GetButtonDown(“Weapon 5“))
            SetActiveWeapon(4);
        if (Input.GetButtonDown(“Weapon 6“))
            SetActiveWeapon(5);
        if (Input.GetButtonDown(“Weapon 7“))
            SetActiveWeapon(6);
        if (Input.GetButtonDown(“Weapon 8“))
            SetActiveWeapon(7);
        if (Input.GetButtonDown(“Weapon 9“))
            SetActiveWeapon(8);

        // 允许用户滚动武器
        if (Input.GetAxis(“Mouse ScrollWheel“) > 0)
            NextWeapon();
        if (Input.GetAxis(“Mouse ScrollWheel“) < 0)
            PreviousWeapon();
    }
    public void SetActiveWeapon(int index)//激活武器的方法
    {
        // 在切换到该武器之前,请确保该武器存在
        if (index >= weapons.Length || index < 0)
        {
            Debug.LogWarning(“试图切换到一个不存在的武器确保你的武器阵列中有正确的武器“);
            return;
        }

        // 发送消息,这样用户就可以在其他情况下进行其他操作
        SendMessageUpwards(“OnEasyWeaponsSwitch“ SendMessageOptions.DontRequireReceiver);

        // 确保武器索引引用正确的武器
        weaponIndex = index;

        // 确保武器切换后没有射束游戏对象
        // weapons[index].GetComponent().StopBeam();

        // 开始停用所有武器
        for (int i = 0; i < weapons.Length; i++)
        {
            weapons[i].SetActive(false);
        }

        // 激活一个我们想要的武器
        weapons[index].SetActive(true);
    }

    public void NextWeapon()//下一个武器
    {
        weaponIndex++;
        if (weaponIndex > weapons.Length - 1)
            weaponIndex = 0;
        SetActiveWeapon(weaponIndex);
    }

    public void PreviousWeapon()//上一个武器
    {
        weaponIndex--;
        if (weaponIndex < 0)
            weaponIndex = weapons.Length - 1;
        SetActiveWeapon(weaponIndex);
    }
}

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2018-11-09 09:52  ChangeArms\
     目录           0  2018-11-09 09:50  ChangeArms\.vs\
     目录           0  2018-11-09 09:50  ChangeArms\.vs\ChangeArms\
     目录           0  2018-11-09 09:50  ChangeArms\.vs\ChangeArms\DesignTimeBuild\
     文件         420  2018-09-14 18:50  ChangeArms\.vs\ChangeArms\DesignTimeBuild\.dtbcache
     目录           0  2018-11-09 09:50  ChangeArms\.vs\ChangeArms\v15\
     文件      134144  2018-11-09 10:23  ChangeArms\.vs\ChangeArms\v15\.suo
     目录           0  2018-11-09 09:50  ChangeArms\.vs\ChangeArms\v15\Server\
     目录           0  2018-11-09 09:50  ChangeArms\.vs\ChangeArms\v15\Server\sqlite3\
     文件       24658  2018-09-14 14:31  ChangeArms\Assembly-CSharp-Editor-firstpass.csproj
     文件       24994  2018-11-09 07:54  ChangeArms\Assembly-CSharp-Editor.csproj
     文件       20390  2018-11-09 07:54  ChangeArms\Assembly-CSharp-firstpass.csproj
     文件       21002  2018-11-09 07:54  ChangeArms\Assembly-CSharp.csproj
     目录           0  2018-11-09 09:50  ChangeArms\Assets\
     文件        7150  2018-09-13 15:51  ChangeArms\Assets\20180913.unity
     文件         155  2018-09-13 15:51  ChangeArms\Assets\20180913.unity.meta
     目录           0  2018-11-09 09:50  ChangeArms\Assets\Arms\
     文件         172  2018-09-14 13:57  ChangeArms\Assets\Arms.meta
     文件      108128  2018-09-14 13:57  ChangeArms\Assets\Arms\Regular_Character.prefab
     文件         190  2018-09-14 13:55  ChangeArms\Assets\Arms\Regular_Character.prefab.meta
     文件        3010  2018-09-14 18:49  ChangeArms\Assets\ChangeArms.cs
     文件         243  2018-09-14 13:49  ChangeArms\Assets\ChangeArms.cs.meta
     目录           0  2018-11-09 09:50  ChangeArms\Assets\Easy Weapons\
     文件         172  2018-09-14 14:08  ChangeArms\Assets\Easy Weapons.meta
     目录           0  2018-11-09 09:50  ChangeArms\Assets\Easy Weapons\Extra\
     文件         193  2016-05-24 14:18  ChangeArms\Assets\Easy Weapons\Extra.meta
     目录           0  2018-11-09 09:50  ChangeArms\Assets\Easy Weapons\Extra\Bomb_Launcher\
     文件         193  2016-05-24 14:14  ChangeArms\Assets\Easy Weapons\Extra\Bomb_Launcher.meta
     文件       46652  2016-05-24 14:16  ChangeArms\Assets\Easy Weapons\Extra\Bomb_Launcher\bomb_launcher.fbx
     文件        1552  2016-05-24 14:16  ChangeArms\Assets\Easy Weapons\Extra\Bomb_Launcher\bomb_launcher.fbx.meta
     文件        2335  2016-05-24 14:16  ChangeArms\Assets\Easy Weapons\Extra\Bomb_Launcher\Bomb_Launcher.prefab
............此处省略1145个文件信息

评论

共有 条评论