Wednesday, January 27, 2016

Post 5


Download here the latest unity project.

- We will add a sound to the player when it gets hit by the enemy.
-Add a AudioSource component to the Player (should be under the Audio components section when you press Add Component)
-Look for a sound in the internet or you can get one Here, open a windows folder with the file in it and drag it into Unity on top of the Project panel where the assets are, this will create a sound clip.
-Select the Player object and drag the sound clip to the audio source component where it says "clip".

-Add this to playerHit (in PlayerController script):
                AudioSource source = this.GetComponent<AudioSource>();
source.Play();
-Run unity we will hear the sound when hit by the enemy.

- You can get a  project with a sample maze Here, now run it and you can see how it works.

- Add a script to the camera then open the script and write this:

using UnityEngine;
using System.Collections;

public class CameraAI : MonoBehaviour {

public GameObject player;

// Use this for initialization
void Start () {

}

// Update is called once per frame
void Update () {
Vector3 pos = this.GetComponent<Transform>().position;
Vector3 playerPos = player.GetComponent<Transform>().position;
pos.x = playerPos.x;
pos.z = playerPos.z;

this.GetComponent<Transform>().position = pos;



}
}

-To add a better effect we place the camera above player close enough so its hard to tell where to go.
-The camera has to  be rotated to point down.


No comments:

Post a Comment