Jump to content
Unity Insider Forum

Gameobject per Script auf Hexagon positionieren


Comm4nd3rCody

Recommended Posts

Hallo,

ich versuche per Script eine Gameobject auf einem Hexagon zu positionieren. Es gelingt mir zwar dieses mittig zu positionieren, aber die Höhe bzw. Z-Koordinate passt nicht.

public void PlaceBuilding(int buildingID)
    {
        //Kopie des Gebäudes erstellen
        GameObject newBuilding = Instantiate(Buildings.ListofBuidlings[buildingID], transform, true);

        //Position des Gebäudes auf dem Hexagontile
        float tilePos_x = 0;
        float tilePos_y = 0;
        float tilePos_z = ((TileMapGenerator.tileMapList[Pos_x,Pos_y].GetComponent<MeshRenderer>().bounds.size.z / 2) / TileMapGenerator.tileMapList[Pos_x, Pos_y].transform.localScale.z) + ((Buildings.ListofBuidlings[buildingID].GetComponent<MeshRenderer>().bounds.size.z / 2) * newBuilding.transform.localScale.z);
        Vector3 buildingPos = new Vector3(tilePos_x, tilePos_y, tilePos_z);
        newBuilding.transform.localPosition = buildingPos;

        buildingSlot = newBuilding;
        slotisFree = false;
    }

Kann mir vielleicht jemand weiterhelfen? Danke schonmal für die Hilfe 🙂

 

Grüße 

Cody

 

Link zu diesem Kommentar
Auf anderen Seiten teilen

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Gast
Auf dieses Thema antworten...

×   Du hast formatierten Text eingefügt.   Formatierung jetzt entfernen

  Only 75 emoji are allowed.

×   Dein Link wurde automatisch eingebettet.   Einbetten rückgängig machen und als Link darstellen

×   Dein vorheriger Inhalt wurde wiederhergestellt.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Lädt...
×
×
  • Neu erstellen...