- Learning C# by Developing Games with Unity 5.x(Second Edition)
- Greg Lukosek
- 244字
- 2021-07-09 20:03:32
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.
- 程序員數學:用Python學透線性代數和微積分
- Getting Started with CreateJS
- Learning Neo4j 3.x(Second Edition)
- Quarkus實踐指南:構建新一代的Kubernetes原生Java微服務
- SQL Server 2016數據庫應用與開發習題解答與上機指導
- Apache Spark 2.x for Java Developers
- C++面向對象程序設計習題解答與上機指導(第三版)
- Java語言程序設計教程
- Unity 3D腳本編程:使用C#語言開發跨平臺游戲
- Java程序設計與項目案例教程
- Data Science Algorithms in a Week
- JavaWeb從入門到精通(視頻實戰版)
- Building Apple Watch Projects
- Java EE 7 Development with WildFly
- HTML5+CSS+JavaScript深入學習實錄