Add various sound effects
This commit is contained in:
30
Assets/Scripts/CollisionSound.cs
Normal file
30
Assets/Scripts/CollisionSound.cs
Normal file
@@ -0,0 +1,30 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
[RequireComponent(typeof(AudioSource))]
|
||||
|
||||
public class CollisionSound : MonoBehaviour
|
||||
{
|
||||
|
||||
public AudioSource audioSource;
|
||||
public AudioClip[] collisionSounds;
|
||||
|
||||
// Start is called before the first frame update
|
||||
void Start()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
private void OnCollisionEnter(Collision collision)
|
||||
{
|
||||
this.audioSource.clip = this.collisionSounds[Random.Range(0, this.collisionSounds.Length)];
|
||||
this.audioSource.Play();
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/CollisionSound.cs.meta
Normal file
11
Assets/Scripts/CollisionSound.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b77cfee0db7d5ec4a87421b180b83cd7
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -3,8 +3,12 @@ using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using UnityEngine.SceneManagement;
|
||||
|
||||
[RequireComponent(typeof(AudioSource))]
|
||||
public class GameManager : MonoBehaviour
|
||||
{
|
||||
public AudioClip goalSound;
|
||||
|
||||
public int scorePlayer1 = 0;
|
||||
public int scorePlayer2 = 0;
|
||||
public int maxGoals = 1;
|
||||
@@ -19,9 +23,11 @@ public class GameManager : MonoBehaviour
|
||||
public Text scoreLabel;
|
||||
public Text winLabel;
|
||||
|
||||
private AudioSource audioSource;
|
||||
// Start is called before the first frame update
|
||||
void Start()
|
||||
{
|
||||
this.audioSource = GetComponent<AudioSource>();
|
||||
this.player1Initial = new GameObject().transform;
|
||||
this.player1Initial.position = this.player1.position;
|
||||
this.player1Initial.rotation = this.player1.rotation;
|
||||
@@ -39,6 +45,8 @@ public class GameManager : MonoBehaviour
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
Debug.Log("Calculating matrix: Vector(" + Time.deltaTime * Random.Range(12, 123) + ")");
|
||||
Debug.Log("Hacking pentagon: in pr0gress...");
|
||||
this.scoreLabel.text = "Score: " + this.scorePlayer1 + " : " + this.scorePlayer2;
|
||||
|
||||
if (this.scorePlayer1 >= maxGoals)
|
||||
@@ -67,6 +75,9 @@ public class GameManager : MonoBehaviour
|
||||
|
||||
public void ResetPositions()
|
||||
{
|
||||
this.audioSource.clip = this.goalSound;
|
||||
this.audioSource.Play();
|
||||
|
||||
this.player1.position = this.player1Initial.position;
|
||||
this.player1.rotation = this.player1Initial.rotation;
|
||||
this.player1.GetComponent<Rigidbody>().velocity = Vector3.zero;
|
||||
|
||||
@@ -14,9 +14,15 @@ public class PlayerController : MonoBehaviour
|
||||
public float boostDuration = 0;
|
||||
public float lastBoostTime = 0;
|
||||
public bool lockBoost = false;
|
||||
public AudioClip boostSound;
|
||||
public Vector2 pitchModifier;
|
||||
|
||||
private AudioSource audioSource;
|
||||
|
||||
// Start is called before the first frame update
|
||||
void Start()
|
||||
{
|
||||
this.audioSource = this.forceZone.transform.GetComponent<AudioSource>();
|
||||
this.rb = GetComponent<Rigidbody>();
|
||||
}
|
||||
|
||||
@@ -27,7 +33,7 @@ public class PlayerController : MonoBehaviour
|
||||
float movementDirection = Input.GetAxis("Vertical" + this.playerNumber);
|
||||
|
||||
if (this.useController) {
|
||||
Debug.Log(Input.GetAxis("VerticalBack" + this.playerNumber));
|
||||
//Debug.Log(Input.GetAxis("VerticalBack" + this.playerNumber));
|
||||
movementDirection = Input.GetAxis("VerticalBack" + this.playerNumber) > 0 ? -1 : movementDirection;
|
||||
}
|
||||
|
||||
@@ -58,8 +64,11 @@ public class PlayerController : MonoBehaviour
|
||||
//Boost
|
||||
if (Input.GetButtonDown("Boost" + this.playerNumber) && !this.lockBoost)
|
||||
{
|
||||
this.audioSource.clip = this.boostSound;
|
||||
this.audioSource.pitch = Random.Range(this.pitchModifier.x, this.pitchModifier.y);
|
||||
this.rb.AddRelativeForce(Vector3.forward * this.boostSpeed * Time.deltaTime, ForceMode.Impulse);
|
||||
this.forceZone.SetActive(true);
|
||||
this.audioSource.Play();
|
||||
this.lastBoostTime = Time.time;
|
||||
this.lockBoost = true;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user