problem with arrays and image replacment
Hi I want to be able to change an image when the player looks at an object and presses a certain key, i have already done the second part but i can't change the Image at the inventory.
CODE:
public Image[] slotsImage;
public GameObject[] inventorySlots;
void Awake(){
inventorySlots = GameObject.FindGameObjectsWithTag ("Slot");
for(int j = 0; j < inventorySlots.Length; j++){
slotsImage [j] = inventorySlots [j].GetComponent<Image> ();
}
}
...
...
public void pickup(){
Destroy (GameObject.Find(seenItem));
ChangeInventorySlot (seenItem);
}
public void ChangeInventorySlot(string iconTitle){
for (int i = 0; i <= slotsImage.Length; i++) {
if(slotsImage[i].sprite == null){
slotsImage[i].sprite = Resources.Load <Sprite>("Icons/" + iconTitle);
i = slotsImage.Length + 1;
}
}
}
Comment
Your answer
Follow this Question
Related Questions
[C#] Array out of bounds 1 Answer
Programatically creating and setting UI image 0 Answers
Why my Image.sprite keeps saying null ?? Help! 0 Answers
if ALL items in array are something 1 Answer
Get length of array C# 3 Answers