当前位置:网站首页>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
边栏推荐
- 【按键消抖】基于FPGA的按键消抖模块开发
- C#(二十九)之C#listBox checkedlistbox imagelist
- Interface idempotency
- 脚本生命周期
- [practical exercise] face location model based on skin color
- Record the pit of NETCORE's memory surge
- An article will give you a comprehensive understanding of the internal and external components of "computer"
- 综合能力测评系统
- Global and Chinese markets for fire resistant conveyor belts 2022-2028: Research Report on technology, participants, trends, market size and share
- Plus d'un milliard d'utilisateurs de grandes entreprises comme Facebook ont été compromis, il est temps de se concentrer sur le did
猜你喜欢
综合能力测评系统
C#(二十九)之C#listBox checkedlistbox imagelist
Chinese brand hybrid technology: there is no best technical route, only better products
Stc8h development (XII): I2C drive AT24C08, at24c32 series EEPROM storage
Record an excel xxE vulnerability
AcWing 243. A simple integer problem 2 (tree array interval modification interval query)
Class A, B, C networks and subnet masks in IPv4
WPF效果第一百九十一篇之框选ListBox
绑定在游戏对象上的脚本的执行顺序
Detailed explanation of serialization and deserialization
随机推荐
20、 EEPROM memory (AT24C02) (similar to AD)
[American competition] mathematical terms
User perceived monitoring experience
Python book learning notes - Chapter 09 section 01 create and use classes
KS008基于SSM的新闻发布系统
简易博客系统
After five years of testing in byte, I was ruthlessly dismissed in July, hoping to wake up my brother who was paddling
综合能力测评系统
Do you know cookies, sessions, tokens?
51nod 1130 n factorial length V2 (Stirling approximation)
DM8 archive log file manual switching
C#(二十九)之C#listBox checkedlistbox imagelist
自动化测试的好处
80% of the diseases are caused by bad living habits. There are eight common bad habits, which are both physical and mental
DM8 backup set deletion
lora网关以太网传输
潘多拉 IOT 开发板学习(HAL 库)—— 实验9 PWM输出实验(学习笔记)
AcWing 243. A simple integer problem 2 (tree array interval modification interval query)
[Zhao Yuqiang] deploy kubernetes cluster with binary package
《2022年中国银行业RPA供应商实力矩阵分析》研究报告正式启动