如何在运行时改变我的搅拌机模型的旋转?

问题描述 投票:0回答:0

当我按下向下键时,恐龙应该蹲下(它确实蹲下了),但它停留在空中并旋转了。我已经检查了模型,它们具有相同的导出选项。同样在场景视图中,可以看到模型没有尝试任何变化。

模型没有动画,我管理从游戏对象到我添加了网格渲染器、网格过滤器和脚本的所有内容。你可以在图片中看到它。

image1 image2

这是我的代码:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class manageTrex : MonoBehaviour {
    public Mesh[] mMeshes;
    public Mesh[] meshDown;
    int num=0,num2=0;
    float velz,velx;

    // Use this for initialization
    void Start () {
        Invoke("trexRun",0.10f);
        GameObject.Find ("Plane").GetComponent<MeshRenderer>().material.mainTexture = Resources.Load("images/sand_dessert") as Texture;
    }
    
    // Update is called once per frame
    void Update () {
        if (Input.GetKey ("right")) {
            velx = -2.5f;
            GameObject.Find ("gobjTrex").transform.Translate(new Vector3(velx*Time.deltaTime,0f,0f));
        }
        if (Input.GetKey ("left")) {
            velx = 2.5f;
            GameObject.Find ("gobjTrex").transform.Translate(new Vector3(velx*Time.deltaTime,0f,0f));
        }

        if (Input.GetKeyDown ("down")) {
            Invoke("trexDown",0.10f);
            CancelInvoke ("trexRun");
        }
        
        if(Input.GetKeyUp ("down")){
            Invoke("trexRun",0.10f);
            CancelInvoke ("trexDown");
        }
    }
    
    void trexRun(){
        string[] arr_model = {"trex_walk_1","trex_walk_2","trex_walk_3"};
        
        if (num > 2) {
            num = 0;
        } else {
            Debug.Log ("acum: "+num+", mesh: "+arr_model[num]);
    
            GameObject.Find("gobjTrex").GetComponent<MeshFilter> ().mesh = mMeshes[num];
            num++;
        }
        Invoke ("trexRun",0.10f);
    }
    
    void trexDown(){
        string[] arr_model = {"trex_down1g2_fbx","trex_down2g2_fbx"};

        if (num2 > 1) {
            num2 = 0;
        } else {
            GameObject.Find("gobjTrex").GetComponent<MeshFilter> ().mesh = meshDown[num2];
            num2++;
        }

        Invoke ("trexDown",0.10f);
    }
}

我试过在导出之前在不同的轴上旋转模型,但结果是一样的。正如你在这张照片中看到的那样。

the problem itself


这就是搅拌机模型的样子:

dinosaur_run

dinosaur_crouch

---------------------------------------- 如果有帮助,这里是这些链接:

3d模型: https://mega.nz/file/nSpGETSQ#4ukMPby5fawUe9F-cStXU4sOTQGU1975fcj9iijgU1I

统一项目: https://mega.nz/file/bOB2lTxa#V05sf8W6D5ayC-xHspuxAzGXg-UeswvOEeP_D5TfU-A

c# unity3d
© www.soinside.com 2019 - 2024. All rights reserved.