create game object dynamically

357
6
04-24-2023 09:15 AM
文言李
New Contributor II

Hi all, 

I had an unity project in which i create some models dynamically, but after I insert map into the project, I can't found the gameobject created by me, anyone can tell me why?

thanks in advance

jeff

0 Kudos
6 Replies
mbd
by
New Contributor II

Hi, I'm thinking of two possibilities:

1. the game object is not a child of the arcgismap object, then the camera doesn't show it.

2. the game object location doesn't have an arcgis location component or is position is far away the origin and extends of the map

I hope it helps!

mbd

0 Kudos
文言李
New Contributor II

Thank you mbd, it's really helpful.

But are all the game objects in arcgismap project be children of arcgismap?

0 Kudos
文言李
New Contributor II

I paste my code here as follows,

public void OnCreateCubeButtonClicked()
{
     Instantiate(myCube, new Vector3(0, 0, 0), Quaternion.identity);
     GameObject arcgixMap = GameObject.Find("ArcGISMap");
     if (arcgixMap != null)
     {
        myCube.transform.parent = arcgixMap.transform;
    }

    HPTransform hpTransform = myCube.GetComponent<HPTransform>();
    if (hpTransform != null)
    {
        hpTransform.LocalPosition = new Unity.Mathematics.double3(-2871978.3959205807,              4132157.7468104535, -4529007.4551753243);
        hpTransform.LocalScale = new Unity.Mathematics.float3(100000, 100000, 100000);
    }
}

Anything wrong?

0 Kudos
Jade
by Esri Contributor
Esri Contributor

You didn't add the location component to your go. 

0 Kudos
文言李
New Contributor II

No, I didn't add component HPTransform, because myCube is a prefab, and I've added the HPTransform component in the inspector.

Another problem is I set the position of hpTransform like this, 

hpTransform.LocalPosition = new Unity.Mathematics.double3(-4451191.8873, 6562076.953, 1046025.930);

button when playing, the position of hpTransform is (6378137, 0, 0)

Any clue?

 

Jeff

0 Kudos
WeiPin
by
New Contributor

嘿!哥们,我搞定了!需要你的Game object在ArcGISMap的层级下面,Game object需要添加两个组件HPTransform、ArcGIS Location。可以通过ArcGIS Location组件修改经纬度。

0 Kudos