I'm currently experiencing an issue with updated coding in C#. I'm working out of a textbook "3.x Game Development Essentials", and am currently attempting to make an array that will have textures assigned to it which will show the progression of a battery being charged to power a door. The textbook wants me to create a GUITexture, however this was made obsolete in a prior Unity update so I instead created a UI Image which created a Canvas and a child Game Object. While this fixed the problem on screen, it took a turn for the worse with coding. The book wants me to create an array of five textures (four states of charge, plus the original empty texture). The goal being whenever the character picks up a power cell, it reflects live in the UI Canvas. Now, here's where I get goobery:
This is the original coding the book specifies to implement on my Inventory script:
public Texture2D [] hudCharge;
public GUITexture charge HudGUI;
I ended up having to get squirrelly to work around old code, and tried this:
using UnityEngine.UI;
public class Inventory : MonoBehaviour{
public static int charge = 0
public UnityEngine.AudioClip collectSound;
public UnityEngine.Texture2D[] hudCharge;
public Image chargeHudGUI;
Now we get even weirder. Because the book is working with out of date code, it wants me to use the value of charge to choose a texture from the array. Thus, it wants me to type:
chargeHudGUI.texture = hudCharge[charge];
the goal being We're addressing the GUITexture object that is assigned to chargeHudGUI variable, specifically its texture property. Well, that'd be groovy but there's no GUITexture anymore so where does that leave me? It leaves me with this:
chargeHudGUI.Image = hudCharge[charge].
I have been looking through every thread I can to try and figure out what to do, but nothing seems to address this particular problem. Does anyone have any pointers for navigating around this nonsense? I've been working on this game for a while now, and I'm determined to finish it out. I want to learn how to use Visual Studio and Unity3D. I appreciate any help!