fixed dialog box array resizing errors
This commit is contained in:
		@@ -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);
 | 
			
		||||
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -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;
 | 
			
		||||
                }
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user