-
Notifications
You must be signed in to change notification settings - Fork 3
08:Put on sounds
The necessary implementation as the game already has almost terminated in the before chapter.
this chapter, implement a sound when it exploded, shot player and BGM.
To simulate the effects of position, Unity requires sounds to originate from Audio Sources attached to objects. The sounds emitted are then picked up by an Audio Listener attached to another object, most often the main camera. Unity can then simulate the effects of a source’s distance and position from the listener object and play them to the user accordingly. The relative speed of the source and listener objects can also be used to simulate the Doppler Effect for added realism.
Drag and drop bgm files to scene view.
Select bgm GameObject and check Loop in inspector.
Please be careful about volume Play game scene. It should be BGM is reproduced with a game start.
Implement a shot sound when a player shoot a bullet.
Attach Audio Source component and set a necessary parameter.
Use Audio Clip in Sound/SE
shoot.
Check is off in Play On Awake, change volume 0.3 and Pitch 0.64
Play shot sound from script.
Player.cs
using UnityEngine;
using System.Collections;
public class Player : MonoBehaviour
{
// Spaceship component
Spaceship spaceship;
IEnumerator Start ()
{
// Get Spaceship component
spaceship = GetComponent<Spaceship> ();
while (true) {
// Shot bullet same position and direction ShotPosition
spaceship.Shot (transform);
// Play shot sound
GetComponent<AudioSource>().Play();
// wait shotDelay/sec
yield return new WaitForSeconds (spaceship.shotDelay);
}
}
void Update ()
{
// Right,left
float x = Input.GetAxisRaw ("Horizontal");
// Up,down
float y = Input.GetAxisRaw ("Vertical");
// Move direction
Vector2 direction = new Vector2 (x, y).normalized;
// Move
spaceship.Move (direction);
}
// Call back when collide
void OnTriggerEnter2D (Collider2D c)
{
// Get layer name
string layerName = LayerMask.LayerToName(c.gameObject.layer);
// Erase bullet when layer name Bullet(Enemy)
if( layerName == "Bullet (Enemy)")
{
// Erase Bullet
Destroy(c.gameObject);
}
// Explosion when layer name Bullet(Enemy) or Enemy
if( layerName == "Bullet (Enemy)" || layerName == "Enemy")
{
// Explosion
spaceship.Explosion();
// Destroy Player
Destroy (gameObject);
}
}
}
Play game scene, It should ring shot sound while player shooting.
Implement an explosion when it exploded.
Attach Explosion sound Sounds/SE
boom to Explosion prefab.
It should be ring explosion sound when explode.
This part is finished. If you get stuck, Download below project file and go next part.
Before you start this tutorials
01:Make sprite and sprite-animation
02:Move player
03:Shooting bullet from player
04:Make enemy
05:Collision Detection, Animation Event, Layer
06:Make background
07:Mechanism making of Wave type
08:Put on sounds
09:Limit player's move and some adjustment
10:Title
11:Enemy HP, bullet power, animation
12:More Waves and add Score
第01回 複数の解像度に対応する(黒帯を追加する)
第02回 複数の解像度に対応する(引き伸ばす)
第03回 タッチパネル対応
第04回 バーチャルジョイスティック対応