Homemade Unity Games tankhero-2d (5) Sound + explosion + scene Toggle + Weapon Ammo

Source: Internet
Author: User

Homemade Unity Games tankhero-2d (5) Sound + explosion + scene Toggle + Weapon Ammo

I am making such a tank game, which is modeled after this game (http://game.kid.qq.com/a/20140221/028931.htm). Only for the purpose of learning unity. Most of the pictures were painted by themselves, and a few were from the Internet. You can get the project source on my GitHub page (Https://github.com/bitzhuwei/TankHero-2D).

This article mainly records sound, scene switching, weapons and ammunition.

About collisions

First, insert a sentence. The previous article recorded the results of the Unity3d collision related experiments. But too long, not practical, after finishing, I summed up the following sentences.

The function of the Rigidbody component is to receive external forces, so as to move itself like a rigid body in physics, and to create forces on other objects.

If the Rigidbody iskinimatic is true, no external forces are received, but the force will continue to be exerted on other objects.

The function of the collider component is to delimit a space range (a rectangle, sphere, grid, etc.), and the Rigidbody component detects whether the collider of two objects is coincident (Enter) continuous (stay) or exit (exit), And inspire both sides of the collision event. If collider is trigger true, the trigger event is fired on both sides.

In short, the scene of moving objects, need rigidbody, always stationary objects, do not need to rigidbody.

Voice

There are 1 Audio listener in the scene to hear the sound. The sound from the Audiosource near the audio listener can be heard.

The background music is generally placed on the main camera.

Occasional sounds, such as picking up gold coins and making "ding" noises. It is possible to use the Audiosource.playclipatpoint method directly.

void ontriggerenter2d(collider2d other)

{

If (other.tag ! = Tags. Hero) { return; }

Audiosource. Playclipatpoint(pickedaudioclip, this. Transform.position, 0.2f);

Monobehaviour. Destroy(this. Gameobject);

}

On the object that holds the Audiosource component, you can see a loudspeaker, which is fun. When the tank was moving, the horn moved along.

Scene switching

I want to keep an object, such as a game controller, as a global thing when I switch scenes. You can use Dontdestroyonload in the script.

void Awake()

{

If (instance = = null)

{

Instance = this;

Dontdestroyonload(this. Gameobject);

}

Else

{

Destroy(this. Gameobject);

}

}

Weapons and ammunition

Weapons and bullets are made into prefab, which can be freely combined. In the inspector is also more convenient to configure.

Summarize

You can get the project source on my GitHub page (Https://github.com/bitzhuwei/TankHero-2D).

Please give me a lot of advice ~

Homemade Unity Games tankhero-2d (5) Sound + explosion + scene Toggle + Weapon Ammo

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.