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