英文:
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<GameObject>(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<GameObject>(path_to_model));
myObj.transform.position = new Vector3(1.5f, 0, 2.3f);
}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论