سؤال

I have a aircraft model and I am able to fly it. I want to move individual parts of aircraft like rudder, propeller, landing gear,etc. and change direction of aircraft in Unity 3d.

هل كانت مفيدة؟

المحلول

if your model has an armature, you can make animations for the armature parented pieces either in unity or in your modeling program, and then through script you can trigger those animations.

EDIT: heres something i found to controll the mesh through script, you can change it to fit your needs, i still say it would be easier to go back into the modeling program and put in an armature and re-export it with an armiture and animations in it already, this is all i can help you

using UnityEngine;
using System.Collections;

[ExecuteInEditMode]

public class VertHandler : MonoBehaviour 
{
    Mesh mesh;
    Vector3[] verts;
    Vector3 vertPos;
    GameObject[] handles;

    void OnEnable()
    {
       mesh = GetComponent<MeshFilter>().mesh;
       verts = mesh.vertices;
       foreach(Vector3 vert in verts)
       {
         vertPos = transform.TransformPoint(vert);
         GameObject handle = new GameObject("handle");
         handle.transform.position = vertPos;
         handle.transform.parent = transform;
         handle.tag = "handle";
         //handle.AddComponent<Gizmo_Sphere>();
         print(vertPos);
       }
    }

    void OnDisable()
    {
       GameObject[] handles = GameObject.FindGameObjectsWithTag("handle");
       foreach(GameObject handle in handles)
       {
         DestroyImmediate(handle);    
       }
    }

    void Update()
    {
       handles = GameObject.FindGameObjectsWithTag ("handle");
       for(int i = 0; i < verts.Length; i++)
       {
         verts[i] = handles[i].transform.localPosition;   
       }
       mesh.vertices = verts;
       mesh.RecalculateBounds();
       mesh.RecalculateNormals();
    }
}
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top