Some tips for Unity3d

Source: Internet
Author: User

Unity in some of the knowledge points are broken, every time you use to go online check, it is a waste of time, the knowledge points together is a good idea, the following is some trivial knowledge points, will gradually update ...

1,gameobject.active indicates whether to deactivate the object in the scene, when Active=false, Gameobject can not find this object, the expression in the editor is the object's inspector inside the display check mark is not checked,

If you start with active=true, and you get the object changed by find, you can setactive (false), and then the object disappears in the scene, and you can still use SetActive (true) to make the object appear again.

2, some of the usage of the camera component is interesting, and the usage can achieve many effects. You can modify the value of the depth, and when there are several cameras in your scene, the camera's field of view with a large depth value will cover the camera's view with a small value,

Using this function can realize the simple version of the small map, first add a camera cam to the scene, adjust the value of the cam depth is larger than the main camera depth, and then adjust the value of viewport rect, w,h,x,y respectively represents the size of width,

Height size, x start position, y start position, their units are in 1 units, we set x=0.8,y=0.8w=0.2,h=0.2 so that cam can be as we see in the end of the tour of the small map as shown in the upper right corner, of course, you can adjust the size of the four values according to the situation.

The culling mask option in the camera will be rendered according to which layer the object is selected, if the layer of an object is "UI" and culling mask does not select the UI, then the object cannot be seen in the scene.

The field of view option in the camera is used to modify the camera's viewing angle size, the larger the value angle, the larger the view, the farther away the object looks, but the projection of the camera must be perspective if the option is to take effect.

With this option, we can modify this value in the code to achieve the object's narrowing and pulling away.

3, collider, trigger and rigid body

The necessary condition for a collision of two objects is that two objects must have a collider (Collider), and one object must also have a rigidbody rigid body. Collider is a number of components, it contains a lot of kinds,

For example: Box Collider (Box collider), Mesh Collider (mesh collider), etc., these collider are applied to different objects on different occasions. The game engine calculates the collision effect based on the collider,

The rigid body lets the object run under the physical effect. A trigger is a property in a collider component that detects whether an object has collided, and unity provides us with an interface:

Trigger Information Detection:

1.monobehaviour.ontriggerenter (Collider Collider) when entering trigger 2. Monobehaviour.ontriggerexit (Collider Collider) when exiting Trigger 3. Monobehaviour.ontriggerstay (Collider Collider) when the stay Trigger collision information detects: 1. Monobehaviour.oncollisionenter (Collision collision) when entering Collider 2. Monobehaviour.oncollisionexit (Collision collision) when exiting Collider 3. Monobehaviour.oncollisionstay (Collision collision) How do we use the above interface when staying in the collider and what are the differences between these interfaces? We do an experiment, create two objects separately, and add collider and rigid body to them respectively, when object A and object B collide, there will be physical effect that collision effect, and will enter the method Oncollisionenter, when we give an object Istrigger tick, Two objects collide again, without physical effects, passing through each other and entering method Ontriggerenter. Through my above narrative, you should have understood the role of the trigger. A trigger can be used if you want to detect an object's contact and not let the collision detection affect the physical state of the object.

Some tips for Unity3d

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.