- Unreal Development Kit Game Programming with UnrealScript:Beginner's Guide
- Rachel Cordone
- 201字
- 2021-08-27 11:59:11
Time for action – Experiments with inheritance
Let's add a variable to our AwesomeGun
class and see how it works with another class we'll create.
- Add an int to our
AwesomeGun
class calledMyInt
. Our code should now look like this:class AwesomeGun extends UTWeap_RocketLauncher_Content; var int MyInt; defaultproperties { FireInterval(0)=0.1 ShotCost(0)=0 }
- Now create another class in our
AwesomeGame/Classes
folder calledAnotherGun.uc
. Type the following code into it: - Compile the code. We'll see that it compiles fine as our
AnotherGun
is inheritingMyInt
fromAwesomeGun
. - Now let's change the class we're extending from to be the same as AwesomeGun's parent class:
class AnotherGun extends UTWeap_RocketLauncher_Content; defaultproperties { MyInt=4 }
- Now when we compile, we'll get a warning:
Warning, Unknown property in defaults: MyInt=4
What just happened?
Even though the classes extend off of the same class, inheritance only happens when the class we want to use the variable in is inside the one that declares the variable in the class tree. We can change the default property of the variable for our class, and this is how we get different functionality out of them such as our example with the firing rate.
推薦閱讀
- Raspberry Pi 3 Cookbook for Python Programmers
- Applied Unsupervised Learning with R
- 電腦常見故障現場處理
- Intel FPGA/CPLD設計(高級篇)
- 深入淺出SSD:固態存儲核心技術、原理與實戰(第2版)
- 平衡掌控者:游戲數值經濟設計
- 單片機開發與典型工程項目實例詳解
- 單片機原理與技能訓練
- IP網絡視頻傳輸:技術、標準和應用
- 單片機原理及應用
- 微服務實戰(Dubbox +Spring Boot+Docker)
- 電腦組裝與硬件維修從入門到精通
- Applied Supervised Learning with R
- Raspberry Pi Media Center
- 基于STM32的嵌入式系統應用