无法在Unity中移动导入的3D模型。

huangapple go评论87阅读模式
英文:

Can't move imported 3D model in Unity

问题

我通过脚本导入了一个自定义的3D模型到我的场景中,我可以看到它。

我使用的代码部分是:

private GameObject myObj;

void Start()
{        
    myObj = Resources.Load<GameObject>(path_to_model);
    Instantiate(myObj);
    myObj.transform.position = new Vector3(1.5f, 0, 2.3f);
}

我可以在正确的位置看到这个对象,但如果我尝试在update()部分内使用Lerp协程来移动它,它不会移动。

**注意:**我已经尝试使用一个基本形状(一个球体)来运行脚本,对象会按要求移动。

英文:

I imported a custom 3D model in my scene via script, and i can visualize it.
The piece of code I used is:

private GameObject myObj;

void Start()
{        
    myObj = Resources.Load&lt;GameObject&gt;(path_to_model);
    Instantiate(myObj);
    myObj.transform.position = Vector3(1.5f, 0, 2.3f);
}

I can see the object in the correct location, but if I try to move it inside the update() section using a coroutine with Lerp, it doesn't move.

NOTE: I already tried the script using a primitive shape (a sphere) and the object moves as required.

答案1

得分: 0

myObj 不应该赋值给模型本身,而应该赋值给该模型的克隆体。

private GameObject myObj;
void Start()
{
    myObj = Instantiate(Resources.Load<GameObject>(path_to_model));
    myObj.transform.position = new Vector3(1.5f, 0, 2.3f);
}
英文:

myObj should not be assigned to the model itself, but to the clone of that model.

private GameObject myObj;
void Start()
{
    myObj = Instantiate(Resources.Load&lt;GameObject&gt;(path_to_model));
    myObj.transform.position = new Vector3(1.5f, 0, 2.3f);
}

huangapple
  • 本文由 发表于 2023年3月15日 21:17:23
  • 转载请务必保留本文链接:https://go.coder-hub.com/75745262.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定