Hi everybody,
I’m learning C# and I don’t really like to bother others with questions, I use google and the forums a lot, but I’m having a lot of trouble trying to figure this out and I can’t make it work. Basically there is some random value generation which creates an Integer that is used as and indexer in VoxelGrid.voxelCordinates(separate script) which equals to a Vector3, after this I add an other Vector3 to the first and I get two Vector3 values. Up to this point everything works but I need those two Vector3 to get stored in that “temp” variable as a pair of Vector3s as declared in the struct and later on add “temp” to a list of structs, called SegemntsList. Doesn’t work, I can’t not even print the values of the Vectors3 contained in “temp”, I’m going bannanas!!!
Here is my code:
2340808–158280–BusySegments.cs (1006 Bytes)
well the struct dosnt define ToString so it likly wont print.
but can you debug log the 2 fields of the struct individually?
Debug.Log(temp.A);
Debug.Log(temp.B);
also you should post your code with code tags instead of attaching it as a file.
here is the code so others can see it with out downloading.
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
public class BusySegments : MonoBehaviour {
public GameObject segmentPrefab;
public int spwQuantity;
public Vector3 origin;
public Vector3 varH;
public static List<Segment> SegmentsList = new List<Segment>();
public struct Segment {
public Vector3 A, B;
public Segment (Vector3 p1, Vector3 p2) {
A = p1;
B = p2;
}
}
private void NewNumberH () {
float spVerticalValue = Random.value;
int spwQuantity = Mathf.RoundToInt (62 * spVerticalValue + 1);
Vector3 origin = VoxelGrid.voxelCordinates[spwQuantity];
Vector3 varH= origin + new Vector3(1,0);
Segment temp = new Segment (origin, varH);
SegmentsList.Add(temp);
print (temp);
GameObject vertex = Instantiate(segmentPrefab) as GameObject;
vertex.transform.localPosition = new Vector3() + origin;
vertex.transform.localRotation = Quaternion.Euler(0f,90f,90f);
}
}
Hey Thanks a lot passerbycmc!!!
Yeah sorry for the mess, I’m very new to this!