Recently, the idea of playing games has emerged , It's out of control , Worked for days , Finally, I did a space shooting with the online course FPS game , I think we should sum it up , For my little white who just touched the game , You can learn a lot from this introduction project .
1. About scripting API Summary of

(1) The first is a lot of ways :MonoBehaviour.OnTriggerExit(), The purpose of this method is to : When Collider( Collisional body ) Stop triggering trigger( trigger ) Called when OnTriggerExit.( You can use this to judge the boundaries of some games , That is, destroy the object when it leaves the boundary )
void OnTriggerExit(Collider other){
Destroy (other.gameObject);
// By the way ,MonoBehaviour Is the base class for all scripts ,js Script inherits this class by default , however C# And Boo It needs to inherit this class explicitly

(2) Another similar method is also commonly used , That is MonoBehaviour.OnTriggerEnter(). When Collider( Collisional body ) get into trigger( trigger ) Called when OnTriggerEnter.
Destroy all objects entering the trigger
void OnTriggerEnter(Collider other) {
These two methods have one thing in common : The message is sent to the trigger and the collider that touches the trigger . Note that if a rigid body is attached to the collider , Send trigger events only .( This sentence is not very understandable )

(3)Transform class : Every object in the scene has one Transform. Location used to store and control objects , Rotate and scale . every last Transform Can have a parent , Allows you to apply location hierarchically , Rotate and scale . You can Hierarchy Panel view hierarchy . They also support counters (enumerator), So you can cycle through sub objects . That is to say, some members of this class can control the size of objects in the scene , Position and other parameters

(4)Transform Attach to GameObject( Game objects )( Empty if no additional ). That's it transform, That is, components Component A variable of , Similar variables are rigidBody,camera wait , stay 5.0 Must pass in version GetComponent<…>() To get components !

(5)RigidBody Rigid body components : A very common component , This component has many useful variables that can be passed through GetComponent(). To use , as rotation,positionvelocity,angulerVelocity( angular velocity ) wait .
void Start () {
// For those with rigid bodies GameObject A speed value
GetComponent ().velocity = transform.forward * speed;
(6)Input class , This class is the input system interface , The function of this class is different on different platforms , Please refer to API, There are several common methods
name): Returns the value in the virtual coordinate system based on the coordinate axis name . Direction has Horizontal and Vertical, The value returned is -1 reach 1 between ;
Input.getButton(string name): Return by button name true When the corresponding virtual button is pressed and held .
Input.getKey(string name): Return when the key specified by name is pressed and held by the user true. Think about automatic fire .
Input.getKeyDown(string name): Return at the frame when the virtual button with given name is pressed true.
Input.getKeyUp(string name): Return at the frame when the user releases the key with the given name true.
(7)Time.deltaTime: Incremental time

Put it in Update() The code in the function is executed in frames . If we need the object to move in seconds . We need to multiply the value of the object's movement by Time.deltaTime. for instance , If we want objects to 10 Move at meter speed , Should be 10*Time.deltaTime, If you don't multiply this , So the object is in every frame 10 Moving at the speed of meters .
(8)Object.Instantiate(): Clone primitive objects , And return the cloned object
clone = Instantiate(object, transform.position, transform.rotation);

(9)MonoBehaviour.InvokeRepeating(): stay time Second call methodName method ; in brief , Call a method with a specified method name based on time , From the first call , every other repeatRate Time call once . That's what happened time After time , every other repeatRate Time call once
function InvokeRepeating (string methodName, float time, float repeateRate)
(10)MomoBehaviour.StartCoroutine() Start collaboration , Here's an official demo to understand
This example demonstrates how to call a coroutine and its execution
function Start() {
// - After 0 seconds, prints “Starting 0.0”
// - After 0 seconds, prints “Before WaitAndPrint Finishes 0.0”
// - After 2 seconds, prints “WaitAndPrint 2.0”
// Print first ”Starting 0.0” and ”Before WaitAndPrint Finishes 0.0” Two sentences ,2 Print in seconds ”WaitAndPrint
print (“Starting ” + Time.time );
// Start function WaitAndPrint as a coroutine. And continue execution while
it is running
// this is the same as WaintAndPrint(2.0) as the compiler does it for you
// Synergetic program WaitAndPrint stay Start In function execution , It can be regarded as the same as Start Function synchronous execution .
print (“Before WaitAndPrint Finishes ” + Time.time );

function WaitAndPrint (waitTime : float) {
// suspend execution for waitTime seconds
// Suspend execution waitTime second
yield WaitForSeconds (waitTime);
print (“WaitAndPrint “+ Time.time );
(11)Update() Methods and FixedUpdate() Differences in methods :
Update Called every time a new frame is rendered ,FixedUpdate, It is executed at fixed time intervals , Not subject to game frame rate (fps) Impact of
FixedUpdate The time interval for can be changed in project settings ,Edit->Project Setting->time find Fixed
timestep. It can be modified !

2. Some experience in the whole process of game making

(1) At the beginning of adding game objects , Be sure to pay attention to the coordinates , We must also pay attention to the difference between world coordinates and local coordinates , Don't drag game objects around , It is necessary to know which object is in which position in the coordinate system
(2) When you write a script, be clear , You can't think of any component, you can add any component , That would cause confusion , Cause problems bug When it's hard

(3) The most important point is : Don't be afraid of trouble , Don't be afraid of difficulties , Playing games is a boring process , Especially the logic in the background , Think clearly , And we should have the spirit of study , Check more if you don't understand API, It's important to understand the principle .

©2019-2020 Toolsou All rights reserved,
One and a half years JAVA Summary of work experience Jsp+Ajax+Servlet+Mysql Add, delete, modify and query ( one ) cartoon | CPU Warfare 40 year , The real king finally appeared ! Don't annoy the panda with any cat !「 Kung Fu Panda 」20 It's the year of man 4 blood IAR Installation and use tutorial Classical algorithm - recursion ( The case of raw rabbit ) Thorough explanation from Zhongtai Random forest R Language implementation R Language cluster analysis case These songs , Programmers, don't listen !