Unity C#语法问题 – Transform 位置

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

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.

huangapple
  • 本文由 发表于 2023年6月29日 07:15:22
  • 转载请务必保留本文链接:https://go.coder-hub.com/76577223.html
匿名

发表评论

匿名网友

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

确定