Quantcast
Viewing latest article 4
Browse Latest Browse All 31

I need help making an image change when I press next

Okay so I have a bestiary page in my game and I made an Entry to for a string (description) as well as a UISprite (using NGUI) for a picture of the beast. I scripted a next button to call a method that cycles through the entry and changes the image and string however I cannot get the image to work. It just stays on the first image. Here's the code: public class Bestiary : MonoBehaviour { public int Page = 0; public UILabel EnemyTitleLabel, EnemyDescriptionTopLabel, EnemyDescriptionBottomLabel; public UISprite EnemyImage; public Entry[] Entries = new Entry[12]; [System.Serializable] public class Entry { public string Title = string.Empty; public string Description = string.Empty; public UISprite Image; public Entry(string title, string description, UISprite image) { Title = title; Description = description; Image = image; } } void Awake() { EnemyImage = GameObject.Find("Enemy Image").GetComponent(); EnemyTitleLabel = GameObject.Find("Enemy Title").GetComponent(); EnemyDescriptionTopLabel = GameObject.Find("Enemy Description Top").GetComponent(); EnemyDescriptionBottomLabel = GameObject.Find("Enemy Description Bottom").GetComponent(); EnemyTitleLabel.text = Entries[0].Title; AssignText(Entries[0].Description); EnemyImage = Entries[0].Image; } private const int TopLabelCharLimt = 200; private void AssignText(string text) { if (text.Length > 200) { string TopText = text.Substring(0, TopLabelCharLimt); string BottomText = text.Substring(TopLabelCharLimt, text.Length); EnemyDescriptionTopLabel.text = TopText; EnemyDescriptionBottomLabel.text = BottomText; } else { EnemyDescriptionTopLabel.text = text; } } public void NextEntry() { if (Page + 1 == Entries.Length) { Page = 0; EnemyTitleLabel.text = Entries[Page].Title; AssignText(Entries[Page].Description); EnemyImage = Entries[Page].Image; } else { Page++; EnemyTitleLabel.text = Entries[Page].Title; AssignText(Entries[Page].Description); EnemyImage = Entries[Page].Image; } } public void PreviousEntry() { if (Page - 1 == -1) { Page = 11; EnemyTitleLabel.text = Entries[Page].Title; AssignText(Entries[Page].Description); EnemyImage = Entries[Page].Image; } else { Page--; EnemyTitleLabel.text = Entries[Page].Title; AssignText(Entries[Page].Description); EnemyImage = Entries[Page].Image; } } }

Viewing latest article 4
Browse Latest Browse All 31

Trending Articles