Search Unity

Multiple meshes access in C#

Discussion in 'Getting Started' started by quintendc, Feb 21, 2019.

  1. quintendc

    quintendc

    Joined:
    Feb 21, 2019
    Posts:
    2
    Hi,

    i have imported an 3d object in Unity that have 2 meshes how can i access these meshes in C#?
    if i do something like gameObject.GetComponent("name of the mesh").tranform.rotate(0, 10, 0);
    this works perfectly this.tranform.rotate(0, 10, 0); but i want to rotate only 1 mesh not whole object.

    i get the error :
    Object reference not set to an instance of an Object C#

    thanks in advance,
     
  2. Ryiah

    Ryiah

    Joined:
    Oct 11, 2012
    Posts:
    21,187
    Transforms are a component of a GameObject (they're always attached which is why you're able to use the shortcut). If you want to control multiple meshes individually then you will need to create multiple GameObjects.
     
  3. quintendc

    quintendc

    Joined:
    Feb 21, 2019
    Posts:
    2
    i was able to manipulate/rotate a part of the gameobject by using this code
    this.transform.find("name of the part").rotate(0,10,0);