Search Unity

prefab is instantitating on to global rather than local coordinates

Discussion in 'Prefabs' started by cloa513, Oct 8, 2021.

  1. cloa513

    cloa513

    Joined:
    Jan 3, 2016
    Posts:
    79
    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;

    public class Making_Tiles: MonoBehaviour
    {
    public GameObject G1;
    public GameObject G2;
    public GameObject G3;
    public GameObject G4;
    public GameObject G5;
    public GameObject G6;
    public GameObject G7;
    public GameObject G8;
    public GameObject G9;
    void Start()
    {
    Instantiate(G1, new Vector3(-4, 4, 0), Quaternion.identity);
    Instantiate(G2, new Vector3(0, 4, 0), Quaternion.identity);
    Instantiate(G3, new Vector3(4, 4, 0), Quaternion.identity);
    Instantiate(G4, new Vector3(-4, 0, 0), Quaternion.identity);
    Instantiate(G5, new Vector3(0, 0, 0), Quaternion.identity);
    Instantiate(G6, new Vector3(4, 0, 0), Quaternion.identity);
    Instantiate(G7, new Vector3(-4, -4, 0), Quaternion.identity);
    Instantiate(G8, new Vector3(0, -4, 0), Quaternion.identity);
    Instantiate(G9, new Vector3(-4, -4, 0), Quaternion.identity);

    }

    upload_2021-10-8_19-7-52.png

    Tiny but you can see Making Tiles is attached to the Large Tile Prefab.

    It runs but puts all the sprites on the global coordinates at the Centre of camera. How to get on to Large Tile local coordinates?
     
  2. pietrodenicola

    pietrodenicola

    Unity Technologies

    Joined:
    Dec 8, 2020
    Posts:
    43
  3. cloa513

    cloa513

    Joined:
    Jan 3, 2016
    Posts:
    79
    Why are you saying scale? I want the gameObjects placed within the local coordinates of the large tile.
     
  4. pietrodenicola

    pietrodenicola

    Unity Technologies

    Joined:
    Dec 8, 2020
    Posts:
    43
    I said "scale" because you said "tiny". It doesn't matter however, because the scale is part of the transform (together with rotation and translation, right?). And as you set the parent, those children will get the coordinates "within the local coordinates" (to use your expression) of the parent (which is the large tile). Try it out. And pay attention to the flag
    worldPositionStays
    , which in your case should be false.
     
  5. cloa513

    cloa513

    Joined:
    Jan 3, 2016
    Posts:
    79
    I said tiny because it is not a great scene shot.
     
    pietrodenicola likes this.