当前位置:网站首页>Several important classes in unity
Several important classes in unity
2022-07-06 04:04:00 【A plum in fall】
List of articles
- Preface
- One 、GameObject class
- Two 、Transform class
- 3、 ... and 、Random class
- Four 、Time class
- 5、 ... and 、Mathf class
- 1. Find the absolute value ABS()
- 2. Find the maximum number or the minimum number MAX() MIN()
- 3. Square root : Sqrt()
- 4. rounding
- 5. Angle and radian values ( Constant values )
- 6. Positive infinity 、 Negative infinity ( Constant values )
- 7. Trigonometric functions :Sin(),Cos(),Tan()...
- 8. Power and exponent :Log()、Log10()、Pow()
- 9. Lerp()
- 10. SmoothDamp()
- 11. MoveTowards()
- 12. PingPong()
- 6、 ... and 、Input class
- Reference source
Preface
This blog lists Unity Some methods in the more important classes in , Not all of them , See API file .
One 、GameObject class
1. Find()
- Find the specified game object through the game object name
- Find() When looking for , As long as it is the game object under the current scene , By default, you can find . And no matter which object the search script is attached to , Can be found . With child parent relationship , You can also find .
- Game object with the same name , You can find several ?
answer : Only one will be found
2. FindWithTag( Tag name )
- I'll just find An object that matches the tag name
- without ,null
- If the specified label is not added in advance , Error message :**** is not defined
3. FindGameObejctsWithTag()
- Find multiple game objects with matching names through tag names
- The return is GameObject An array of types
- You can traverse the returned array and other operations
- Get an array with a length of : call Length
4. Create game objects
5. SetActive( true );
6. GetComponent(typeOf(Transform))
- Generics are recommended GetComponent< >
Two 、Transform class
Properties in this class
1. parent
Get the parent object of the current game object
2. root
Get the top level of the current game object
3. localPosition
Get the location of the local coordinate system
4. GetInstanceID
Get the current GameObject's id( Unique )
5. childCount
Get the number of sub objects
Methods in this class
1. GetChild( int index )
Gets the GameObject
2. IsChildOf ()
Determine whether it is a child of the specified object
3. Find()
Look for objects
4. Translate()
Move in the specified direction and position
i. (x , y , z)
ii. Vector3.left|right|up|down|forward|back
Such as : Move to the left 1 A unit
transform.Translate(-1,0 , 0);
transform.Translate(Vector3.left);
transform.Translate() Function , The first variable is the speed of the object , The velocity here is a vector , Both case and direction , The latter variable is the relative coordinate system , The relative coordinate system here has two values , One is the world coordinates , One is its own coordinates , If the first coordinate is not filled in , The default is its own coordinate system .
notes :Space.self | world
transform.Translate(Vector3.up * Time.deltaTime, Space.Self);
5. Rotate()
Rotate at the specified angle
Rotate( Parameters 1, Parameters 2)
Rotate the cube , With Y The axis rotates in the positive direction with the center point .
transform.Rotate(Vector3.up);
transform.Rotate(Vector3.up * Time.deltaTime);
transform.Rotate(Vector3.up * Time.deltaTime * speed);
Rotate the cube , With X The axis rotates as the center .
transform.Rotate(Time.deltaTime, 0, 0);
transform.Rotate(Time.deltaTime * speed, 0, 0);
6.LookAt()
Make the current object face the target position
Inherited from the parent class Component
1. attribute :name, gameObject, tag, transform…
2. GetComponent<>()
3. GetComponentInChildren<> ()
4. Instantiate
5. Instantiate ( The original object )
Instantiate( The original object , The location of the new object , The angle of the new object )
The method is Unity Medium Object Class
Used to generate a copy of the specified game object
When method execution is finished , A copy of the object will be treated as Object Type return
This method is generally written in Update() In the method , Usually under specific conditions , Otherwise, the method will be executed all the time , Carton . Such as : Click the left mouse button or a key on the keyboard , Will produce a copy …
notes : If the position and rotation angle of the new object are not specified through the second and third parameters , Then by default, a new object will be generated in the same position as the original object ( The new object will overwrite the original object )
3、 ... and 、Random class
Random class : Pseudo random number
1. seeds
2. Range()
Random.Range (min, max): What happened was min To max Random numbers in the range include min, But it doesn't include max
3. give an example
snake
Four 、Time class
1. deltaTime
float Return value
It takes time to execute from the previous frame ( decimal )
Two use scenarios :
1) Rotate or move , It's quite fast ,*deltaTime Control the speed
2)Update() Time mismatch caused by frame rate ,
FixedUpdate()— object ( rigid body )
resolvent :
transform.Translate(Vector3.up * Time.deltaTime)
2. time
Can be placed in update It calculates the time from the beginning to the moment
3. timeScale
Pause
5、 ... and 、Mathf class
Provides a series of methods and attributes for mathematical operations
1. Find the absolute value ABS()
2. Find the maximum number or the minimum number MAX() MIN()
3. Square root : Sqrt()
4. rounding
Round()
Returns the rounded to the nearest integer /f/.
9.1 Round to the nearest 9
9.5 rounding 10
-9.1 rounding -9
-9.4 rounding -9
-9.5 rounding -10
Ceil()
Returns greater than or equal to f Minimum integer of .
Floor()
Returns less than or equal to f Maximum integer for .
If this number is positive , After rounding : Integral part
If this number is negative , After rounding : reduce 1, Such as :-9.1 result :-10
5. Angle and radian values ( Constant values )
Deg2Rad
1 How many radians does the angle equal
Rad2Deg
1 How many angles does radian equal
6. Positive infinity 、 Negative infinity ( Constant values )
Infinity
print Coming out is Infinity
NegativeInfinity
print Coming out is -Infinity
7. Trigonometric functions :Sin(),Cos(),Tan()…
8. Power and exponent :Log()、Log10()、Pow()
9. Lerp()
stay a And b Press... Between t Linear interpolation .
10. SmoothDamp()
Gradually change a value to the desired goal over time .
11. MoveTowards()
Will value current towards target near .
12. PingPong()
PingPong Returns a value , The value will be at the value 0 And length Between increasing and decreasing . Type table tennis .
6、 ... and 、Input class
Mouse input
Input Class provides related properties and methods for processing mouse input
1. mousePostion
Get the specific coordinates of the mouse on the current screen
It's a two-dimensional coordinate (Z Axis is always 0)
The coordinates are related to the current screen pixels
If the mouse is in the lower left corner of the current screen , Then for (0,0)
If the mouse is in the upper right corner of the screen , Then for (Screen.Width, Screen.Height)
notes : The current screen refers to the current Game window
2. GetMouseButtonDown( Key code )
When the specified mouse button code is pressed , return true
otherwise , return false
Such as :
if(Input.GetButtonDown(2))
{
print(Random.Range(0,10); //[0,10)
}
else
{
print(Random,Range(-10,0)) ///[-10,0)
}
Left mouse button :0
Right mouse button :1
Middle of mouse :2
Judge whether the middle mouse button is pressed currently , If you press , return [0,10) Random number between , Otherwise return to [-10,0)
3. GetMouseButtonUp( Key code )
When the specified mouse button code is pressed , return true
otherwise , return false
Generally, before implementing this method , Press first , Then lift
4. GetMouseButton( Key code )
When the specified mouse is pressed all the time , return true
otherwise , return false
5. GetAxis(“Mouse X”)
Method returns float Data of type
Get the distance the mouse moves horizontally
When the mouse moves along the positive half axis in the horizontal direction , Get a positive number
When the mouse moves on the negative half axis in the horizontal direction , Get a negative number
6. GetAxis(“Mouse Y”)
Method returns float Data of type
Get the distance the mouse moves in the vertical direction
When the mouse moves on the positive half axis in the vertical direction , Get a positive number
When the mouse moves on the negative half axis in the vertical direction , Get a negative number
Keyboard entry
Input
1. GetKeyDown( Keyboard keys )
Specify when a keyboard key is pressed , return true, otherwise , return false
2. GetKeyUp( Keyboard keys )
Specify when a keyboard key is lifted , return true, otherwise , return false
3. GetKey( Keyboard keys )
Specify that a keyboard key is pressed all the time , return true, otherwise , return false
notes : Key code of keyboard keys
i. “*****”
Such as "a"
ii. KeyCode
Such as KeyCode.A
4. GetAxis(“Horizontal”)
Used to judge the horizontal direction key on the keyboard
5. GetAxis(“Vertical”)
It is used to judge which vertical direction key on the keyboard is pressed
If the method returns 0 To 1 A positive number between , It means pressing the up direction
If the method returns 0 To -1 Negative numbers between , Indicates that the downward direction is pressed
return -1 To 1 Decimal between
Reference source
Official documents :API file
Reference video : Darnay Education Unity Basics
Reference material : Netizens' notes
边栏推荐
- Développement d'un module d'élimination des bavardages à clé basé sur la FPGA
- Basic knowledge of binary tree, BFC, DFS
- Differential GPS RTK thousand search
- [prediction model] difference method model
- Python book learning notes - Chapter 09 section 01 create and use classes
- asp. Core is compatible with both JWT authentication and cookies authentication
- 80% of the diseases are caused by bad living habits. There are eight common bad habits, which are both physical and mental
- KS008基于SSM的新闻发布系统
- Leetcode32 longest valid bracket (dynamic programming difficult problem)
- Yyds dry goods inventory web components series (VII) -- life cycle of custom components
猜你喜欢

Ethernet port &arm & MOS &push-pull open drain &up and down &high and low sides &time domain and frequency domain Fourier

math_极限&微分&导数&微商/对数函数的导函数推导(导数定义极限法)/指数函数求导公式推导(反函数求导法则/对数求导法)

Security xxE vulnerability recurrence (XXe Lab)

cookie,session,Token 这些你都知道吗?

Stc8h development (XII): I2C drive AT24C08, at24c32 series EEPROM storage

What is the difference between gateway address and IP address in tcp/ip protocol?

Ks003 mall system based on JSP and Servlet

Facebook等大廠超十億用戶數據遭泄露,早該關注DID了

C form application of C (27)

Blue Bridge Cup - Castle formula
随机推荐
【按鍵消抖】基於FPGA的按鍵消抖模塊開發
Why do you want to start pointer compression?
在 .NET 6 中使用 Startup.cs 更简洁的方法
MySQL transaction isolation level
Global and Chinese markets for patent hole oval devices 2022-2028: Research Report on technology, participants, trends, market size and share
Introduction to data types in MySQL
[analysis of variance] single factor analysis and multi factor analysis
Plus d'un milliard d'utilisateurs de grandes entreprises comme Facebook ont été compromis, il est temps de se concentrer sur le did
Basic knowledge of binary tree, BFC, DFS
WPF效果第一百九十一篇之框选ListBox
User datagram protocol UDP
10個 Istio 流量管理 最常用的例子,你知道幾個?
Cf603e pastoral oddities [CDQ divide and conquer, revocable and search set]
10个 Istio 流量管理 最常用的例子,你知道几个?
MySql數據庫root賬戶無法遠程登陸解决辦法
Global and Chinese markets for MRI safe implants 2022-2028: technology, participants, trends, market size and share Research Report
2/10 parallel search set +bfs+dfs+ shortest path +spfa queue optimization
MySql数据库root账户无法远程登陆解决办法
KS003基于JSP和Servlet实现的商城系统
Conditionally [jsonignore]