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];
}
*/
}
}
}