- Learning C# by Developing Games with Unity 3D Beginner's Guide
- Terry Norton
- 263字
- 2021-08-04 10:03:59
Components communicating using the Dot Syntax
Our script has variables to hold 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 GameObject's Components and another GameObject's Components 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 the 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.
That's called the Dot Syntax. The following is another example. It's the fictitious address of my house: USA.Vermont.Essex.22MyStreet
Looks funny, doesn't it? That's because I used the syntax (grammar) of C# instead of the post office. However, I'll bet if you look closely, you can easily figure out how to find my house. We'll get into much more Dot Syntax detail in Chapter 6, Using Dot Syntax for Object Communication.
Pop quiz – knowing the C# building blocks
Q1. What is the purpose of a variable in a script?
Q2. What is the purpose of a method in a script?
Q3. How does a script become a Component?
Q4. What is the purpose of Dot Syntax?
- JavaScript修煉之道
- 前端跨界開發指南:JavaScript工具庫原理解析與實戰
- 匯編語言程序設計(第2版)
- Mastering Julia
- Python機器學習編程與實戰
- C語言程序設計學習指導與習題解答
- HTML5+CSS3網頁設計
- Getting Started with NativeScript
- Spring Boot企業級項目開發實戰
- Learning DHTMLX Suite UI
- Windows Phone 7.5:Building Location-aware Applications
- UVM實戰
- C和C++游戲趣味編程
- Go語言精進之路:從新手到高手的編程思想、方法和技巧(2)
- Hadoop 2.X HDFS源碼剖析