Unity3d I used the little Thing (ii)

Source: Internet
Author: User

XI. Click events

Picture Add a touch physics2d, associated script void OnMouseDown () {} function click on Enter


12. Collision Detection

Two photos encounter interaction want to do something

Add a component collider to the picture, Componet->physics->box Colider (Colider are collider, the difference is in the shape of different, I used Box, add the picture body has a green frame, if the model with mesh more accurate)

The IS trigger option that comes with the component is selected, similar to the switch

Add a component to a picture rigid body, componet->physics->rigidbody

(the use gravity supplied with the component is canceled, is kinematic selected)

Collision function

Note: The colliding objects need to follow the above steps, and the next is to add the collider and the rigid body is the same, there are physics and physics2d, choose the same, I have suffered

Note: Script a inherits the script b,b inside the collision function does not use A,a to rewrite directly, does not have the tube other, applies a, together even collision function inherits

13. Tag Benefits

Played cocos2d people know, tag equivalent alias, particularly useful, we operate conveniently, I do not know how to describe, Unity3d began to bring a tag is the player, the protagonist, that is, a common tag

Create a new tag:edit->projectsettings->tags and Layers, in the inspector window there are tags,size you want a few, here is the name tag, create

Add tag to the picture: After selecting the picture in the inspector window tag, you have created your own tag and player

Use 1: Attach the Tag object, point out the tag, the quotation mark is tag, 12 and 42 graph combination means the object that added this script collision to add tag for player or tag for playerrocket object words ...

Use 2:gameobject.findgameobjectwithtag ("Tag") to get other game objects Gameobject can click to find Tag


14, incremental time Time.deltatime

This is a time-per-second calculation, especially useful

If you control the picture move float i = time.deltatime*2f; move Speed 2 m per second

Add you want to make the picture disappear after 5 seconds i=5;i-=time.deltatime;if (i<=0) ... 5 Seconds later ...


XV, Awake () function

void Awake () {}; This function is called an earlier function (the name I started ...). Did not find what to call), because you know to run first in the start () function, but if you use this function, before entering start, enter this function


16. Skills

Transform components with a very wide, back I in summary, and now all the early morning, I first summed up a about this technique, audio components, and some of the same can be used this technique

We use this component is usually this point out, in the update function more than a few times, internal ... Inefficient, build a variable of this type, in the start () function is first assigned value, later with this variable, is the same, the efficiency is fast


17. Audio (Add music to object)

1. Add Audio component: Component->audio->audio Source

2. Create an audio variable public audioclip m_shootclip; Easy to drag the music you want on the Unity screen

3.m_audio. Playoneshot (m_shootclip); This line of code is, M_audio is written according to 16, all the notation is This.audio, the parentheses add audio variables



Unity3d I used the little Thing (ii)

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.