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

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.

主站蜘蛛池模板: 孝感市| 尼勒克县| 尚志市| 九龙县| 南岸区| 铁岭市| 扶风县| 柏乡县| 新源县| 棋牌| 米林县| 枣庄市| 昆山市| 中西区| 博罗县| 射阳县| 德昌县| 德清县| 昌都县| 莒南县| 杨浦区| 玉屏| 鲁山县| 闸北区| 潮州市| 南皮县| 红原县| 阳山县| 聂荣县| 平舆县| 剑阁县| 边坝县| 天全县| 丹寨县| 祥云县| 益阳市| 陇川县| 渑池县| 遂川县| 芜湖市| 垦利县|