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 GameManiac · Oct 22, 2015 at 12:02 PM · arrayintitemactivate

Need help checking if an item slot is filled

Hello everybody, so I have an issue with some code my friend wrote. So my issue is figuring out how to activate a Power up once it has been stored into a slot, via a button press. I don't necessarily know where to look and have looked at this code over and over to try to figure it out but I may just not be focusing in the right area. there is a piece of commented out code that i wrote to try to piece it together but im not sure that it is the right code.

 using UnityEngine;
 using System.Collections;
 using UnityEngine.UI;
 using Rewired;
 
 public class TestController : MonoBehaviour {
     private PowerUp[] StoredPowerUps = new PowerUp[4];
     private int NumberStoredPowerUps = 0;
     public PowerUp ActivePowerUp;
     public bool IsShuffling = false;
     private float ShuffleTimeOut = 5f;
     private float CurrentTimer = 0f;
     public PowerUp[] ShuffleList;
     public Image ShuffleIcon;
     public float ShuffleDelay = 0.05f;
     public float CurrentShuffleDelay = 0f;
     private int ShuffleIndex = -1;
     [SerializeField]
     private int PlayerId;
     private Player player;
     
     
     // Use this for initialization
     void Start () {
         player = ReInput.players.GetPlayer (PlayerId);
     }
     
     // Update is called once per frame
     void Update () {
         
         if (IsShuffling) {
             if(ShuffleIndex == -1){
                 ShuffleIndex = Random.Range(0,ShuffleList.Length);
             }
             CurrentShuffleDelay += Time.deltaTime;
             if(CurrentShuffleDelay >= ShuffleDelay){
                 CurrentShuffleDelay = 0f;
                 ShuffleIndex++;
                 if(ShuffleIndex >= ShuffleList.Length){
                     ShuffleIndex = 0;
                 }
                 ShuffleIcon.sprite = ShuffleList[ShuffleIndex].image;
             }
             CurrentTimer += Time.deltaTime;
             if(player.GetButton("StopPower") || CurrentTimer >= ShuffleTimeOut){
                 IsShuffling = false;
                 Debug.Log("S");
                 if(ShuffleList[ShuffleIndex].autofire){
                     ActivePowerUp = ShuffleList[ShuffleIndex];
                     Debug.Log("Activated "+ActivePowerUp.name);
                 }else{
                     int StoredIndex = NumberStoredPowerUps++;
                     if(StoredIndex < 4){
                         StoredPowerUps[StoredIndex] = ShuffleList[ShuffleIndex];
                         Debug.Log("Stored "+StoredPowerUps[StoredIndex].name+" in slot "+StoredIndex);
                     }
                 }
                 ShuffleList = null;
                 ShuffleIndex = -1;
                 CurrentTimer = 0f;
                 
             }
             /*
             if(player.GetButton("Power1") && StoredPowerUps[0]){
                 ActivePowerUp = ShuffleList[ShuffleIndex];
                 StoredPowerUps[StoredIndex] = ShuffleList[ShuffleIndex];
             }
             */
         }                
     }
 }
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 GameManiac · Oct 22, 2015 at 10:21 PM

Nevermind everybody figured it out i was slightly correct with my commented out code but had to change a couple of things here is what i wrote for those interested:

 //Begin use stored
         if(player.GetButton("Power1") && StoredPowerUps[0] != null){
             ActivePowerUp = StoredPowerUps[0];
             StoredPowerUps[0] = null;
             Debug.Log("Activated "+ActivePowerUp.name);
         }
         if(player.GetButton("Power2") && StoredPowerUps[1] != null){
             ActivePowerUp = StoredPowerUps[1];
             StoredPowerUps[1] = null;
             Debug.Log("Activated "+ActivePowerUp.name);
         }
         if(player.GetButton("Power3") && StoredPowerUps[2] != null){
             ActivePowerUp = StoredPowerUps[2];
             StoredPowerUps[2] = null;
             Debug.Log("Activated "+ActivePowerUp.name);
         }
         if(player.GetButton("Power4") && StoredPowerUps[3] != null){
             ActivePowerUp = StoredPowerUps[3];
             StoredPowerUps[3] = null;
             Debug.Log("Activated "+ActivePowerUp.name);
         }
 //End Use Stored
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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

How do I modify values in an array from a different C# script ? 1 Answer

NullReferenceException: Object reference not set to an instance of an object & You are trying to create a MonoBehaviour using the 'new' keyword. 0 Answers

Custom Editor from a Non-Monobehavior Script 0 Answers

Pull int from string if within square brackets 1 Answer

trying to get an Array string to read an Int 0 Answers


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