当前位置:网站首页>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
边栏推荐
- [adjustable delay network] development of FPGA based adjustable delay network system Verilog
- 如何修改表中的字段约束条件(类型,default, null等)
- How to modify field constraints (type, default, null, etc.) in a table
- Global and Chinese markets for MRI safe implants 2022-2028: technology, participants, trends, market size and share Research Report
- How does technology have the ability to solve problems perfectly
- Ethernet port &arm & MOS &push-pull open drain &up and down &high and low sides &time domain and frequency domain Fourier
- MySQL master-slave replication
- Oracle ORA error message
- Benefits of automated testing
- Fundamentals of SQL database operation
猜你喜欢
TCP/IP协议里面的网关地址和ip地址有什么区别?
[Zhao Yuqiang] deploy kubernetes cluster with binary package
STC8H开发(十二): I2C驱动AT24C08,AT24C32系列EEPROM存储
【FPGA教程案例11】基于vivado核的除法器设计与实现
Align items and align content in flex layout
cookie,session,Token 这些你都知道吗?
[Massey] Massey font format and typesetting requirements
Maxay paper latex template description
Ethernet port &arm & MOS &push-pull open drain &up and down &high and low sides &time domain and frequency domain Fourier
记一次excel XXE漏洞
随机推荐
Record the pit of NETCORE's memory surge
Global and Chinese markets for MRI safe implants 2022-2028: technology, participants, trends, market size and share Research Report
Alibaba testers use UI automated testing to achieve element positioning
Stack and queue
Blue Bridge Cup - day of week
TCP/IP协议里面的网关地址和ip地址有什么区别?
[FPGA tutorial case 11] design and implementation of divider based on vivado core
自动化测试怎么规范部署?
Ks003 mall system based on JSP and Servlet
cookie,session,Token 这些你都知道吗?
C#(三十一)之自定义事件
SSTI template injection explanation and real problem practice
自动化测试的好处
Fundamentals of SQL database operation
Global and Chinese market of rubber wheel wedges 2022-2028: Research Report on technology, participants, trends, market size and share
[Massey] Massey font format and typesetting requirements
The Research Report "2022 RPA supplier strength matrix analysis of China's banking industry" was officially launched
/usr/bin/gzip: 1: ELF: not found/usr/bin/gzip: 3: : not found/usr/bin/gzip: 4: Syntax error:
Mathematical modeling regression analysis relationship between variables
10個 Istio 流量管理 最常用的例子,你知道幾個?