using System.Collections; using System.Collections.Generic; using UnityEngine; public class Cameretta : MonoBehaviour { // Start is called before the first frame update static GameObject pareti; static internal Vector3 sSP; static Vector3 sPDX; static Vector3 pPDX; static Vector3 pPN; static Vector3 sPN; static Vector3 sP3; static Vector3 sP4; string nome; static internal void ok() { Debug.LogFormat("ok in...."); } static internal Vector3 PosizionaObjectMain(string objName, Vector3 objScale, Vector3 objPos, Vector3 rifObjectScale, string[] piuOmeno) { pareti = GameObject.Find($"{objName}"); sPN.x = objScale.x; sPN.y = objScale.y; sPN.z = objScale.z; pareti.transform.localScale = new Vector3(sPN.x, sPN.y, sPN.z); pPN = new Vector3(); if (piuOmeno[0] == "+") { pPN.x += (rifObjectScale.x / 2) - (sPN.x / 2); } else if (piuOmeno[0] == "-") { pPN.x -= (rifObjectScale.x / 2) - (sPN.x / 2); } if (piuOmeno[1] == "+") { pPN.y += (rifObjectScale.y / 2) + (sPN.y / 2); } else if (piuOmeno[1] == "-") { pPN.y -= (rifObjectScale.y / 2) + (sPN.y / 2); } if (piuOmeno[2] == "+") { pPN.z += (rifObjectScale.z / 2) - (sPN.z / 2); // piu sull'asse z con riferimento object } else if (piuOmeno[2] == "-") { pPN.z -= (rifObjectScale.z / 2) - (sPN.z / 2); } //pPN.z += (rifObjectScale.z / 2) - (sPN.z / 2); pareti.transform.position = new Vector3(pPN.x, pPN.y, pPN.z); return pPN; } void Start() { sSP.x = 500; // ^^^^^^^^^ Riferimento Object per posizionamento ^^^^^^^^^^^ sSP.y = 20; sSP.z = 400; transform.localScale = new Vector3(sSP.x, sSP.y, sSP.z); // Scala pavimento int i = 0; while (i < 5) { i++; pareti = GameObject.CreatePrimitive(PrimitiveType.Cube); nome = "parete"; pareti.name = $"{nome} {i}"; //pareti.transform.parent = transform; } pareti = GameObject.Find($"{nome} 1"); sPDX.x = 10; sPDX.y = 270; sPDX.z = 400; pareti.transform.localScale = new Vector3(sPDX.x, sPDX.y, sPDX.z); // Scala parete DX pPDX.x += (sSP.x / 2) - (sPDX.x / 2); pPDX.y += (sSP.y / 2) + (sPDX.y / 2); pPDX.z += (sSP.z / 2) - (sPDX.z / 2); pareti.transform.position = new Vector3(pPDX.x, pPDX.y, pPDX.z); // x = 239.5f pareti = GameObject.Find($"{nome} 2"); PosizionaObjectMain(pareti.name, sPDX, new Vector3(), sSP, new string[] {"-", "+", "+"}); /*pareti.transform.localScale = new Vector3(sPDX.x, sPDX.y, sPDX.z); pPDX = new Vector3(); pPDX.x -= (sSP.x / 2) - (sPDX.x / 2); pPDX.y += (sSP.y / 2) + (sPDX.y / 2); pPDX.z += (sSP.z / 2) - (sPDX.z / 2); pareti.transform.position = new Vector3(pPDX.x, pPDX.y, pPDX.z); */ pareti = GameObject.Find($"{nome} 3"); sPDX.x = 410; sPDX.y = 270; sPDX.z = 10; PosizionaObjectMain(pareti.name, sPDX, new Vector3(), sSP, new string[] {"+", "+", "+"}); sP3 = pareti.transform.localScale; /*sPDX.x = 410; sPDX.y = 270; sPDX.z = 10; pareti.transform.localScale = new Vector3(sPDX.x, sPDX.y, sPDX.z); pP3 = pareti.transform.localScale; pPDX = new Vector3(); pPDX.x += (sSP.x / 2) - (sPDX.x / 2); pPDX.y += (sSP.y / 2) + (sPDX.y / 2); pPDX.z += (sSP.z / 2) - (sPDX.z / 2); pareti.transform.position = new Vector3(pPDX.x, pPDX.y, pPDX.z); */ pareti = GameObject.Find($"{nome} 4"); sPDX.x = 80; sPDX.y = 60; sPDX.z = 10; pareti.transform.localScale = new Vector3(sPDX.x, sPDX.y, sPDX.z); PosizionaObjectMain(pareti.name, sPDX, new Vector3(), sSP, new string[] {"+", "+", "+"}); sP4 = pareti.transform.localScale; pPDX = new Vector3(); pPDX.x += (sSP.x / 2) - (sPDX.x / 2) - sP3.x; pPDX.y += (sSP.y / 2) + (sPDX.y / 2) + (sP3.y - sPDX.y); pPDX.z += (sSP.z / 2) - (sPDX.z / 2); pareti.transform.position = new Vector3(pPDX.x, pPDX.y, pPDX.z); pareti = GameObject.Find($"{nome} 5"); sPDX.x = 10; sPDX.y = 210; sPDX.z = 10; pareti.transform.localScale = new Vector3(sPDX.x, sPDX.y, sPDX.z); PosizionaObjectMain(pareti.name, sPDX, new Vector3(), sSP, new string[] {"+", "+", "+"}); pPDX = new Vector3(); pPDX.x += (sSP.x / 2) - (sPDX.x / 2) - sP3.x - sP4.x + sPDX.x; pPDX.y += (sSP.y / 2) + (sPDX.y / 2) + sP3.y - sPDX.y - sP4.y; pPDX.z += (sSP.z / 2) - (sPDX.z / 2); pareti.transform.position = new Vector3(pPDX.x, pPDX.y, pPDX.z); // posizione parete DX = + (xSP / 2) - o + (xSPDX / 2) Formula posizionamento su superficie oggetto RetroLetto.Start(); } // Update is called once per frame void Update() { } }