unity3d中切换武器


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
//NextWeapon.js ---------------------------------------------------------- By Henry Xie
 
//宣告 : 使用介面模版、武器順序、目前及下一個武器(取得名稱用)、3把武器、二個前段介面文字
var  MySkin : GUISkin;
var  WeaponSort : int = 0;
private  var CurrentWeapon : GameObject;
private  var NextWeapon : GameObject;
var  Weapon0 : GameObject;
var  Weapon1 : GameObject;
var  Weapon2 : GameObject;
var  FrontText1 = "切換武器為 : ";
var  FrontText2 = "目前武器名稱/順序 : ";
 
//介面功能 : 如果按下切換武器按鈕時,武器順序加1 --------------------------------------
//介面文字 : 目前武器名稱/順序 + / + 目前武器名稱
function  OnGUI()
{
    GUI.skin = MySkin;
    if (GUI.Button(Rect(20, 200, 150, 30), FrontText1 + NextWeapon.name))
    {
       WeaponSort ++;
    }
    GUI.Label(Rect(200, 5, 300, 30), FrontText2 + CurrentWeapon.name + "/"  + WeaponSort);
}
 
//功能 : 每個 frame 都執行一次 --------------------------------------------------------
//如果武器順序為0,則目前武器為武器0;下一把武器為武器1;開啟武器0;關閉武器1及2,以此類推
//如果武器順序大於等於3,則歸0 (形成循環)
function  Update()
{
    if (WeaponSort == 0)
    {
       CurrentWeapon = Weapon0;
       NextWeapon = Weapon1;
       Weapon0.active = true ;
       Weapon1.active = false ;
       Weapon2.active = false ;
    }
    if (WeaponSort == 1)
    {
       CurrentWeapon = Weapon1;
       NextWeapon = Weapon2;
       Weapon0.active = false ;
       Weapon1.active = true ;
       Weapon2.active = false ;
    }
    if (WeaponSort == 2)
    {
       CurrentWeapon = Weapon2;
       NextWeapon = Weapon0;
       Weapon0.active = false ;
       Weapon1.active = false ;
       Weapon2.active = true ;
    }
    if (WeaponSort >= 3)
    {
       WeaponSort = 0;
    }
}
 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM