英文:
Unity C# Syntax question - Transform Position
问题
以下是要翻译的部分:
"为什么会这样?"
我正在参加Create with code课程,目前在一个部分,我需要让主摄像机跟随玩家。我已经让摄像机工作了,但想要稍微调整位置,所以我认为这会起作用:
void Update()
{
transform.position = player.transform.position + Vector3 (0,5, -5);
}
在观看视频后,我发现我需要在文本中添加new,这样它才能这样说:
void Update()
{
transform.position = player.transform.position + *new* Vector3 (0,5, -5);
}
为什么会这样?我明白这是一个新的向量,但我正在尝试理解这一点,并找出我可以在哪里学到更多关于正确语法的知识 - 我猜想是文档吧?
英文:
What is the reason behind this?
I'm doing the Create with code course and am at a part where I have the main camera follow the player. I got the camera to work but wanted to offset the position slightly so I thought this would work:
void Update()
{
transform.position = player.transform.position + Vector3 (0,5, -5);
}
After Watching the video, I see that I needed to add new to the text so that it could say this.
void Update()
{
transform.position = player.transform.position + *new* Vector3 (0,5, -5);
}
What is the reason behind this? I get that it is a new vector, but I'm trying to reason this and find out where I could learn more on proper syntax - I assume the documentation?
答案1
得分: 1
"vector3"为空。需要进行新分配。
"new vector3"用于创建vector3结构。
因为"vector3"是一个结构体,所以需要创建一个新的来使用。
英文:
"vector3" is empty. A new assignment is required.
"new vector3" is used to create vector3 struct.
Because "vector3" is a struct, you need to create a new one to use.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论