- Home /
Having a problem with collecting powercell and script
So I have written this code to the allowed player to track how many powercell is been collected and allowed a player to open a door. some reason it's giving me an error on the line where it saying hudCharge[charge]; and line meterCharge[Charge]. for that error it's saying cannot apply indexing [] to an expression of type 'Texture2D'
Also I think I got some array variable in this script so I can modify those in unity to hold a reference to the texture that need to show. and I also don't get any option in unity to add a texture Can someone fix it for me
using System.Collections; using System.Collections.Generic; using UnityEngine;
 public class CountPowerCell : MonoBehaviour {
 
     public int charge = 0;
     public AudioClip collectSound;
 
     //HUD
     public Texture2D hudCharge;
     public GUITexture chargeHudGUI;
 
     //Generator
     public Texture2D meterCharge;
     public Renderer meter;
 
     public void Start()
     {
         charge = 0;
     }
 
     public void Update()
     {
 
     }
 
     public void CellPickup()
     {
         HUDon();
         AudioSource.PlayClipAtPoint(collectSound, transform.position);
         charge++;
         chargeHudGUI.texture = hudCharge[charge];
         meter.material.mainTexture = meterCharge[Charge];
     }
    public  void HUDon()
     {
         if (!chargeHudGUI.enabled)
         {
             chargeHudGUI.enabled = true;
         }
     }
 
 }
               Comment
              
 
               
              Your answer
 
 
              koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                