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

3D grid with little cube inside another ?

Discussion in 'Scripting' started by zenden_1, May 15, 2019.

  1. zenden_1

    zenden_1

    Joined:
    May 20, 2017
    Posts:
    53
    Actually i made a simple version of a cube game building system but when i set little cube i have issue with the value to round.

    _blocKPosRound = 0.0625

    Scale of little cube is 0.125f

    Scale of the big cube is 0.5f

    Code (CSharp):
    1. if(Input.GetMouseButtonDown(1))          
    2.             {
    3.                 GameObject fBlock = Instantiate(selectedBlock,Vector3.one,hit.transform.rotation);
    4.                 float roundT = hit.transform.lossyScale.x;
    5.  
    6.                 Debug.DrawRay(cam.transform.position,point,Color.red,10f);
    7.  
    8.                 print("Valeur AB : " + point.x);
    9.                 print("Valeur 1 : " + Mathf.Round(point.x));
    10.                 print("Valeur 2 : " + Mathf.Round(point.x / _blocKPosRound));
    11.                 print("Valeur 3 : " + Mathf.Round(point.x / _blocKPosRound)  * _blocKPosRound);
    12.  
    13.                
    14.  
    15.                
    16.                 Vector3 _position = new Vector3(
    17.                 Mathf.Round(point.x / _blocKPosRound) * _blocKPosRound,
    18.                 Mathf.Round(point.y / _blocKPosRound) * _blocKPosRound,
    19.                 Mathf.Round(point.z / _blocKPosRound) * _blocKPosRound);
    20.  
    21.                 fBlock.GetComponent<Renderer>().material.color = Random.ColorHSV();
    22.  
    23.  
    24.                 fBlock.transform.position = _position;
    25.  
    26.  
    27.             }
    The issue is the blue cube.