- Home /
Question by
IronStarInteractive · Jan 24, 2017 at 08:06 AM ·
arrayvector3arraysempty
Vector3 Array Empties Its Self Immediately After Being Initialized
I seem to have a problem with my array of Vector3s every time i run the program and print the array slots there all empty even if i print it on the next line I've looked at answers that say how to do it and they don't seem to work either,
here is the code
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Test : MonoBehaviour {
Vector3[] vec3 = new Vector3[7];
void Start () {
// Initialize Array
vec3[0] = new Vector3(0f,0.008f,0f);
vec3[1] = new Vector3(0f,0.003f,0.007f);
vec3[2] = new Vector3(0f,0.003f,0.007f);
vec3[3] = new Vector3(0f,-0.006f,0.002f);
vec3[4] = new Vector3(0f,0.004f,0.03f);
vec3[5] = new Vector3(0f,0f,0.015f);
vec3[6] = new Vector3(0f,0f,-0.01f);
// Print Array
print(vec3[0]);
print(vec3[1]);
print(vec3[2]);
print(vec3[3]);
print(vec3[4]);
print(vec3[5]);
print(vec3[6]);
}
}
all help is appreciated.
Comment
Best Answer
Answer by Peaj · Jan 24, 2017 at 09:24 AM
Your Array is not empty.
By default the output of a float gets rounded to 1decimal place. Try to output the values like this and you will see they are not empty (just very small):
print(vec3[0].ToString("0.000"));
Thank you so much i finally found out what the problem was it didn't have anything to do with array being empty after all, but because the print said that it was zero i thought it must have been the array.
once again Thanks ;D