unity3d中切换武器

//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;

   }

}







你可能感兴趣的:(unity3d)