当前位置:网站首页>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
边栏推荐
- Facebook and other large companies have leaked more than one billion user data, and it is time to pay attention to did
- Plus d'un milliard d'utilisateurs de grandes entreprises comme Facebook ont été compromis, il est temps de se concentrer sur le did
- C#(三十一)之自定义事件
- 51nod 1130 n factorial length V2 (Stirling approximation)
- 【可调延时网络】基于FPGA的可调延时网络系统verilog开发
- [matlab] - draw a five-star red flag
- [prediction model] difference method model
- Network security - Security Service Engineer - detailed summary of skill manual (it is recommended to learn and collect)
- Global and Chinese markets for otolaryngology devices 2022-2028: Research Report on technology, participants, trends, market size and share
- [Massey] Massey font format and typesetting requirements
猜你喜欢
Error 1045 (28000): access denied for user 'root' @ 'localhost' (using password: no/yes
Web components series (VII) -- life cycle of custom components
MySql數據庫root賬戶無法遠程登陸解决辦法
WPF效果第一百九十一篇之框选ListBox
P7735-[noi2021] heavy and heavy edges [tree chain dissection, line segment tree]
Viewing and verifying backup sets using dmrman
C (XXIX) C listbox CheckedListBox Imagelist
C language -- structs, unions, enumerations, and custom types
Interface idempotency
[meisai] meisai thesis reference template
随机推荐
如何修改表中的字段约束条件(类型,default, null等)
Unity中几个重要类
asp. Core is compatible with both JWT authentication and cookies authentication
MySql数据库root账户无法远程登陆解决办法
Codeforces Round #770 (Div. 2) B. Fortune Telling
在 .NET 6 中使用 Startup.cs 更简洁的方法
How to standardize the deployment of automated testing?
【leetcode】1189. Maximum number of "balloons"
Fundamentals of SQL database operation
JVM的手术刀式剖析——一文带你窥探JVM的秘密
[practical exercise] face location model based on skin color
Introduction to data types in MySQL
Ks003 mall system based on JSP and Servlet
How can programmers resist the "three poisons" of "greed, anger and ignorance"?
Basic knowledge of binary tree, BFC, DFS
KS003基于JSP和Servlet实现的商城系统
综合能力测评系统
P2648 make money
【FPGA教程案例11】基于vivado核的除法器设计与实现
AcWing 243. A simple integer problem 2 (tree array interval modification interval query)