fixed dialog box array resizing errors

This commit is contained in:
Sam 2023-05-06 18:49:45 -07:00
parent 05cf1c729b
commit c13793565d
2 changed files with 13 additions and 3 deletions

View File

@ -22,10 +22,11 @@ public class DialogBoxes : MonoBehaviour
// Start is called before the first frame update
void Start()
void Awake()
{
textField = this.gameObject.GetComponent<TMP_Text>();
ReconfigureSpriteArray();
print("reconfigured");
textField.text = dialogMessages[0];
backgroundImageObject.sprite = images[0];
}
@ -35,6 +36,8 @@ public class DialogBoxes : MonoBehaviour
messageCount += 1;
if (messageCount < dialogMessages.Length)
{
print("looking at message " + messageCount);
print("messages: " + dialogMessages.Length + ", images: " + images.Length);
textField.text = dialogMessages[messageCount];
backgroundImageObject.sprite = images[messageCount];
}
@ -50,13 +53,19 @@ public class DialogBoxes : MonoBehaviour
void ReconfigureSpriteArray()
{
print("attempting to reconfigure");
// resize if need to
if (images.Length != dialogMessages.Length)
{
print("resizing");
Sprite[] newImagesArray = new Sprite[dialogMessages.Length];
for (int i = 0; i < newImagesArray.Length; i++)
{
newImagesArray[i] = images[i];
if (i < images.Length) {
newImagesArray[i] = images[i];
} else {
newImagesArray[i] = null;
}
}
images = newImagesArray;
}
@ -69,6 +78,7 @@ public class DialogBoxes : MonoBehaviour
images[i] = images[i - 1];
}
}
print(images.Length);
}
}

View File

@ -47,7 +47,7 @@ public class EnemyPatrol : MonoBehaviour {
void Update() {
if (!pinned) {
if (isHorizontal) {
if (transform.position.x >= xRight || transform.position.x <= xLeft) {
if (transform.position.x > xRight || transform.position.x < xLeft) {
movementVectorHorizontal = -movementVectorHorizontal;
GetComponent<SpriteRenderer>().flipX = !GetComponent<SpriteRenderer>().flipX;
}