Unity3d weapons Switching

Source: Internet
Author: User
// Nextweapon. JS -------------------------------------------------------- by Henry Xie // Declaration: Use the Interface Template, weapon sequence, current and next weapon (for name registration) 3. Weapons and two front-end interface text 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 = "Currently, the weapons are named"; // interface function: if you add 1 ---------------------------------------------------------- in sequence when you press the: currently, the weapon name is ready/sorted +/+ the current weapon name is called 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);} // function: each frame is sent once ------------------------------------------------------ // if the weapon sequence is 0, the current weapon is 0; the next weapon is weapon 1; the other weapons are 0; the other weapons are 1 and 2, which are pushed as follows // if the weapon sequence is greater than 3, otherwise, 0 (forming a cycle) 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 ;}}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.