zoukankan      html  css  js  c++  java
  • 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;
       }
    }
     
  • 相关阅读:
    How to function call using 'this' inside forEach loop
    jquery.validate.unobtrusive not working with dynamic injected elements
    Difference between jQuery.extend and jQuery.fn.extend?
    Methods, Computed, and Watchers in Vue.js
    Caution using watchers for objects in Vue
    How to Watch Deep Data Structures in Vue (Arrays and Objects)
    Page: DOMContentLoaded, load, beforeunload, unload
    linux bridge
    linux bridge
    EVE-NG网卡桥接
  • 原文地址:https://www.cnblogs.com/android-blogs/p/6038484.html
Copyright © 2011-2022 走看看