Search Unity

Static object transform matrix

Discussion in 'Scripting' started by bovesan, Apr 21, 2018.

  1. bovesan

    bovesan

    Joined:
    Nov 30, 2017
    Posts:
    5
    I need to access a static object's transform matrix. It's working fine in the editor, but it seems to do nothing at runtime. This following test shows me the transform position and scale values are correct, but the TransformPoint is not. LocalToWorldMatrix is not working neither.

    Code (CSharp):
    1.  
    2.         private void OnDrawGizmosSelected()
    3.         {
    4.             Gizmos.color = Color.red;
    5.             foreach (MeshFilter meshFilter in target.GetComponentsInChildren<MeshFilter>()){
    6.                 MeshRenderer meshRenderer = meshFilter.GetComponent<MeshRenderer>();
    7.                 //Debug.Log(string.Format("position: {0} scale: {1}", meshFilter.transform.position, meshFilter.transform.lossyScale));
    8.                 foreach (Vector3 vertex in BoundsVertices(meshFilter.sharedMesh.bounds)){
    9.                     Gizmos.DrawSphere(meshFilter.transform.TransformPoint(vertex), 0.02f);
    10.                 }
    11.             }
    12.         }
    13.  
    How can I do this without having non-static duplicates of all my meshes?

    PS: This is in 2017.3.1f1
     
    Last edited: Apr 21, 2018