官术网_书友最值得收藏!

Components that communicate using dot syntax

Our script has variables for holding data, and our script has methods to allow tasks to be performed. I now want to introduce the concept of communicating with other GameObjects and the components they contain. Communication between one components GameObject and another component GameObject using dot syntax is a vital part of scripting. It's what makes interaction possible. We need to communicate with other components or GameObjects to be able to use the variables and methods in other components.

What's with the dots?

When you look at code written by others, you'll see words with periods separating them. What the heck is that? It looks complicated, doesn't it. The following is an example from the Unity documentation:

transform.position.x
Note

Don't concern yourself with what the preceding code means, as that comes later. I just want you to see the dots.

This is called dot syntax. The following is another example. It's the fictitious address of my house: UnitedKingdom, Bedfordshire, Sandy, 10MyStreet. Looks funny, doesn't it? That's because I used the syntax (grammar) of C# instead of the post office. However, I'll bet that, if you look closely, you can easily figure out how to find my house. We'll get into much more at a later stage. For now, think of dot syntax as an address, starting from a big thing, a country in this case, and narrowing down to the most precise part that we want to access.

主站蜘蛛池模板: 宁蒗| 苏尼特左旗| 那曲县| 剑川县| 霍州市| 汾西县| 和硕县| 南投市| 河北区| 卢湾区| 商水县| 上饶市| 蒙城县| 屏南县| 寻甸| 夏津县| 溧水县| 建水县| 陆丰市| 辽阳市| 富裕县| 西畴县| 集安市| 兰州市| 崇文区| 乌拉特前旗| 广宁县| 兴义市| 乌苏市| 桂平市| 永吉县| 呼图壁县| 浪卡子县| 左权县| 湘西| 西乌珠穆沁旗| 横山县| 安化县| 磐石市| 陆川县| 麦盖提县|