Search Unity

need help with a concept of racing track modules

Discussion in 'Scripting' started by Zyntherius, May 30, 2016.

  1. Zyntherius

    Zyntherius

    Joined:
    Nov 3, 2012
    Posts:
    6
    Hello :D,

    I'm developing a modular track editor. I want so create modules for the track as in slot car racing track.
    My modules will be 3d-models with special properties like name, ID, description, V3 Start Point and V3 End Point. My question now is: What's the best way to give the 3d-models these properties?


    My so far solution is to create a Prefab with a Model and a Script:
    (this way was inspired by an inventory-system)

    Code (csharp):
    1.  
    2.  
    3. [System.Serializable]
    4. public class Modul
    5. {
    6.     public string modulName;
    7.     public int modulID;
    8.     public string modulDesc;
    9.     public Texture2D modulIcon;
    10.     public float modulLength;
    11.     public ModulType modulType;
    12.  
    13.     public List<Segment> Segments;  
    14. // custom datatype Segment (contains a V3 position and Quat rotation)
    15. // using as [0] start point and [1] end point
    16.  
    17.     public Vector3[] originCurve;
    18.     public float length;
    19.  
    20. public enum ModulType
    21.     {
    22.         Default,
    23.         TrackPart,
    24.         Decoration,
    25.         Special
    26.     }
    27.  
    :(
    Sadly I don't know any better solution so far. Important for me is especially that I have the exact end points and start points of the module so that I can put the track parts together seamlessly.


    Does anyone have a different solution or am I on the right track? - Thanks
     
  2. gorbit99

    gorbit99

    Joined:
    Jul 14, 2015
    Posts:
    1,350
    I mean, a class would be the perfect solution in my opinion, because it can contain the track, the start and end points, and you can write some handy methods for it too (maybe even one, that creates said track)
     
  3. Zyntherius

    Zyntherius

    Joined:
    Nov 3, 2012
    Posts:
    6
    Thanks for your opinion! I will take your advice :)