I am a beginner.

I am writing a C # script in Unity

First, we created a cube object using CreatePrimitive.

Next, after converting the String type array to the float type using Parse,
I'm trying to change the size of cube by substituting 3 elements of the array into Vector3, but it doesn't work very well.

How do you make an array retain its value after passing a for statement?

Error message

Error message

Applicable source code
Source code
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Test1: MonoBehaviour
    public GameObject cube;
    public float [] FloatDate;
    public string [] Date;

    void Start ()
        string [] Date = {"1.05", "1.2", "7.0", "9.5"};

        for (int n = 0;n<Date.Length;n ++)
            float [] FloatDate = new float [Date.Length];
            FloatDate [n] = float.Parse (Date [n]);
        cube = GameObject.CreatePrimitive (PrimitiveType.Cube);
        cube.transform.localScale = new Vector3 (FloatDate [0], FloatDate [1], FloatDate [2]);
Supplemental information (FW/tool version etc.)

The OS uses Windows 8.1.

  • Answer # 1

    This is becauseFloatDateis redeclared as a local variable in the

    for statement.
    Don't redeclare, please make new outside the for statement.