如何为主摄像机添加RectTransform功能?

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

How to add RectTransform function for Main Camera?

问题

我需要将RectTransform函数绑定到主摄像机上,但控制台报错CS1002。
也许我在主摄像机入口处犯了一个错误。你能帮忙吗?
以下是引发错误的代码部分:

    RectTransform recT = content.GetComponent<RectTransform>();
    RectTransform recT = Main Camera.GetComponent<RectTransform>();
    recT.transform.localPosition = new Vector3(0.0f, 0.0f, 0.0f);
    _group = GetComponent<VerticalLayoutGroup>();
    setAchievs();

我尝试过不仅通过空格写Main Camera,还尝试了下划线和结合在一起,但都没有帮助。

英文:

I need to bind the RectTransform function to the Main Camera, but the console throws error CS1002.
Perhaps I made a mistake in the Main Camera entry. Can you help?
Here is the part of the code that throws the error:

RectTransform recT = content.GetComponent<RectTransform>();
RectTransform recT = Main Camera.GetComponent<RectTransform>();
recT.transform.localPosition = new Vector3(0.0f, 0.0f, 0.0f);
_group = GetComponent<VerticalLayoutGroup>();
setAchievs();

I tried to write Main Camera not only through a space, but also through an underscore and together, but it didn’t help

答案1

得分: 1

在代码的第3行,出现了一个错误,即CS1002,它表示您忘记了加分号。因为您在代码行中缺少了一个空格,它应该是Main Camera,而不是MainCamera,如果您已引用了它。否则,应该是:

Camera.main.GetComponent<RectTransform>();

以获取MainCamera的RectTransform。

希望这有所帮助。

英文:

You have an error in the code line number 3 i,e CS1002 which represents that you have forgot to put semicolon. Because you have missed a Space in the Line that says Main Camera it should have been MainCamera if you have referenced it. Otherwise it should be

Camera.main.GetComponent<RectTransform>();
to get the MainCamera's RectTransform.

Hope this helps.

huangapple
  • 本文由 发表于 2023年1月9日 19:34:17
  • 转载请务必保留本文链接:https://go.coder-hub.com/75056685.html
匿名

发表评论

匿名网友

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

确定