Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
  • Help Room /
avatar image
0
Question by sipSups · Feb 16, 2017 at 01:20 PM · meshmodelsshopguns

Gun shop - gun doesn't switch pleaseee help

Hello! I am trying to build a gun shop. on this script, everything is working, the gun itself (its properties i mean) is changing, but the model is not.. this is my script. i have set up the array of gameobjects with guns that have skinned mesh renderers attached to them, but now when i buy a gun, it doesn't delete the default gun (gun number 0), it just puts the gun that i bought next to it, without destroying the default gun. why is this? using UnityEngine; using System.Collections; using UnityEngine.UI;

  public class WeaponButton : MonoBehaviour
  {
  
  
      public GameObject[] weaponObjects;
      public PlayerShooting playerShooting;
      public MoneyManager moneyManager;
  
      public int weaponNumber;
      public Image image;
     // public Text name;
      public Text cost;
      //public Text description;
      public Text alreadyHave;
      public Text purchaseComplete;
      public Text insufficient;
  
    
      public int activeCount;
      public Slider damageSlider;
      public Slider timeSlider;
      
  
      private AudioSource source;
  
    
      // Use this for initialization
      void Start()
      {
  
          
          moneyManager = GameObject.FindGameObjectWithTag("Money").GetComponent<MoneyManager>();
          
  
          source = GetComponent<AudioSource>();
          SetButton();
  
          purchaseComplete.enabled = false;
          alreadyHave.enabled = false;
  
          SwitchWeapon(0);
  
  
  
  
          
      }
  
      void SetButton()
      {
          string costString = playerShooting.weapons[weaponNumber].cost.ToString();
          //name.text = playerShooting.weapons[weaponNumber].name;
          cost.text = "$" + playerShooting.weapons[weaponNumber].cost;
          //description.text = playerShooting.weapons[weaponNumber].description;
          timeSlider.maxValue = 0.7f;
          timeSlider.value = timeSlider.maxValue - playerShooting.weapons[weaponNumber].fireRate;
          damageSlider.value =  playerShooting.weapons[weaponNumber].damage;
          
  
  
          if (playerShooting.weapons[weaponNumber].doHaveit)
          {
              image.color = new Color32(98, 74, 139, 255);
          }
      }
  
      public void BuyItem()
      {
          if(playerShooting.weapons[weaponNumber] == playerShooting.weapons[playerShooting.currentWeapon])
          {
              StartCoroutine(ShowAlreadyHave());
          }
  
          if (playerShooting.weapons[weaponNumber].doHaveit)
          {
  
  
              
              playerShooting.currentWeapon = weaponNumber;
  
              SwitchWeapon(weaponNumber);
  
  
  
  
              StartCoroutine(ShowAlreadyHave());
  
          }
          else if (moneyManager.totalMoney >= playerShooting.weapons[weaponNumber].cost && !playerShooting.weapons[weaponNumber].doHaveit)
          {
  
              
              moneyManager.totalMoney -= playerShooting.weapons[weaponNumber].cost;
              playerShooting.currentWeapon = weaponNumber;
             
              playerShooting.weapons[weaponNumber].doHaveit = true;
  
              SwitchWeapon(weaponNumber);
  
  
              StartCoroutine(ShowPurchase());
              Social.ReportProgress("CgkInf3suvQWEAIQCw", 100.0f, (bool success) => { });
  
  
          }
          else if(moneyManager.totalMoney < playerShooting.weapons[weaponNumber].cost)
          {
              StartCoroutine(ShowInsufficient());
          }
  
  
          
  
      }
  
      IEnumerator ShowAlreadyHave()
      {
          insufficient.enabled = false;
          purchaseComplete.enabled = false;
          alreadyHave.enabled = true;
          yield return new WaitForSeconds(3);
          alreadyHave.enabled = false;
      }
      IEnumerator ShowPurchase()
      {
          insufficient.enabled = false;
          alreadyHave.enabled = false;
          purchaseComplete.enabled = true;
          yield return new WaitForSeconds(3);
          purchaseComplete.enabled = false;
      }
      IEnumerator ShowInsufficient()
      {
          purchaseComplete.enabled = false;
          alreadyHave.enabled = false;
          insufficient.enabled = true;
          yield return new WaitForSeconds(3);
          insufficient.enabled = false;
      }
  
      private void Update()
      {
          if (playerShooting.weapons[weaponNumber].doHaveit)
          {
              image.color = new Color32(255, 255, 255, 255);
          }
  
      }
  
      void SwitchWeapon(int index)
      {
  
          for (int i = 0; i < weaponObjects.Length; i++)
          {
              if (i == index)
              {
                  
                  weaponObjects[i].GetComponent<SkinnedMeshRenderer>().enabled = true;
              }
              else
              {
                  
                  weaponObjects[i].GetComponent<SkinnedMeshRenderer>().enabled = false;
              }
          }
      }
 
  
  }
Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by sipSups · Feb 16, 2017 at 02:22 PM

PROBLEM FIXED - on my array, array item number 3 was empty, so it jumped but then got out of bounds.. something weird yeah.. this was the problem all along! Don't use EMPTY ARRAYS ON GAMEOBJECTS guys.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

96 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Сonvert the model (*.NMO) from VirTools to the Unity mesh model, 1 Answer

Can't Remove Character Head From FPS Cam - Model is a Single Mesh 1 Answer

Obj model invisible in game 0 Answers

How to create a 3D Hemisphere? (Model of half a sphere) 0 Answers

Mesh texture doesn't applies correctly 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges