Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

basic question about assets placement (changed the question)

Discussion in 'Scripting' started by pachermann, Jul 9, 2017.

  1. pachermann

    pachermann

    Joined:
    Dec 18, 2013
    Posts:
    133
    Hi everyone, i have basic questions.
    i found out that my orignal Question was a bit dumb, so i made it better.

    So i change the question.

    What i wanna achieve is that i can load street patches assets.
    In order to position them i need the world coordinates of the last set street patch.

    i could not figure out how to make a function in order to do that.

    its about this line (in my public void loadStreetPatch() ):
    Code (csharp):
    1.  
    2. // store actual patch postions
    3.         ActualPatchPosition = instance.transform.position; <!--- this position
    4.  
    So i get always vector3(0,0,0) what is the default postion of the asset, but i want the position inside the Scene.

    what i wanted was to add a new new Vector3(10f, 0, 0) that adds plus 10f to axis.X


    // for each new patch i want to add 10f in axis.X plus the current positon of the last patches right corner positon.
    Code (csharp):
    1.  
    2.  
    3.     instance.transform.position = lastPolyAssetPosition + new Vector3(10f, 0, 0);
    4.  
    5.  
    Code (csharp):
    1.  
    2.   // if found load assets inside PolyAssets Folder (resources)
    3.     public void loadStreetPatch() {
    4.  
    5.         // creates an instance of the loaded obj on the scene
    6.         GameObject instance = Instantiate(Resources.Load("PolyAssets/street_patch_10m_straight",
    7.         typeof(GameObject))) as GameObject;
    8.  
    9.         //The created instance needs to be silbling of the AssetResourceLoader Go in hierarchy
    10.         instance.transform.SetParent(this.transform);
    11.  
    12.  
    // in the next code section i get the transform.position but as it seems i get always the original position vector3(0,0,0)

    1. Question: how do i get the last assets coordinates vector3

    this gives me the 0,0,0 that is where my failure lies:
    ActualPatchPosition = instance.transform.position;

    Code (csharp):
    1.  
    2.         // store actual patch postions
    3.         ActualPatchPosition = instance.transform.position;
    4.  
    5.         // first patch is always at Vector3 10f,0,0
    6.         if(patchCounter == 1)  {
    7.  
    8.           instance.transform.position = DefaultPolyAssetPosition + new Vector3(10f, 0, 0);
    9.         } else {
    10.         // the second is on 10f,0,0
    11.           instance.transform.position = ActualPatchPosition + new Vector3(10f, 0, 0);
    12.         }
    13.  
    14.     }
    15.  
    would be very nice if you guys could help me a bit on how to do a function like this.
    Code (csharp):
    1.  
    2.  
    3. for each time a patch gets Instantiate {
    4. add the last added patches coordinates vector3 + new vector3(10f,0,0)
    5. }
    6.  
    7.  

    best,
    pascal
     
    Last edited: Jul 9, 2017