Problem with Char Array

I am essentially trying to create a word game where the char array will take the string and break it down into characters. This all works fine. The problem I am having is that for some reason the letters are not displaying correctly, as shown in the screenshots below. There are no other scripts in the scene at this time, and the script is attached to the main camera.

Game View:

Console View:
5202311--517352--upload_2019-11-22_13-9-1.png

Inspector View:
5202311--517355--upload_2019-11-22_13-9-21.png

Code:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class Word_Generator : MonoBehaviour
{
    [SerializeField] private char [] char_Word;

    [SerializeField] private GameObject go_Anchor;
    [SerializeField] private GameObject go_Letter;
    [SerializeField] private List <GameObject> go_Letters = new List <GameObject> ();

    [SerializeField] private string str_Word;

    private void Start ( )
    {
        str_Word = str_Word.ToUpper ( );
        char_Word = str_Word.ToCharArray ( );

        for ( int int_LetterCount = 0; int_LetterCount <= char_Word.Length; int_LetterCount++ )
        {
            if ( char_Word [ int_LetterCount ] == ' ' )
            {
                // Insert Code For Space
                Debug.Log ( "Space" );
            }

            else
            {
                // Instantiate the Letter Space
                go_Letters.Add ( go_Letter );
                Instantiate ( go_Letters [ int_LetterCount ], new Vector3 ( go_Anchor.transform.position.x, go_Anchor.transform.position.y, go_Anchor.transform.position.z ), Quaternion.identity, GameObject.Find ( "Canvas" ).transform );

                // Set Letter
                go_Letters [ int_LetterCount ].GetComponentInChildren<Text> ( ).text = char_Word [ int_LetterCount ].ToString ( );

                // Make Space
                go_Anchor.transform.position = new Vector3 ( go_Anchor.transform.position.x + 110, go_Anchor.transform.position.y, go_Anchor.transform.position.z );

                Debug.Log ( go_Letters [ int_LetterCount ].GetComponentInChildren<Text> ( ).text );
            }
        }
    }
}

What’s not correct here? Letters are the same and code looks valid.

It should say AND not DAN.

I don’t understand why on lines 33 and 36 you’re getting the letter from the go_Letters list by index when you already have a direct reference to it you’re using on line 32 (go_Letter). On line 33 you’re instantiating go_Letters[int_LetterCount] but you’re not capturing the result, and instead on line 36 and 39 you’re making changes to the prefab instead of the instantiated GameObject.

I’m also concerned that not every iteration of your for loop will result in a new letter (when the “if” statement on line 23 is true), which means a letter won’t be added to the go_Letters list, but then you’re using int_LetterCount as an index for the list. This will result in index out of range errors.

Are you sure that you assigned the Letter Space elements in the correct order?

A string is an array of characters, and can be directly treated as such.

string charArray = "asdf";
Debug.Log(charArray[0]); // "a"

Edit to add: I also see you’re using Hungarian Notation in your variable names. This is pointless, and just makes your code hard to read, as well as other problems.