New Audio script
This commit is contained in:
@@ -435,7 +435,7 @@ Transform:
|
|||||||
m_PrefabAsset: {fileID: 0}
|
m_PrefabAsset: {fileID: 0}
|
||||||
m_GameObject: {fileID: 711422030}
|
m_GameObject: {fileID: 711422030}
|
||||||
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
|
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
|
||||||
m_LocalPosition: {x: -43.7, y: 16.2, z: -8.24259}
|
m_LocalPosition: {x: -43.7, y: 14, z: -8.24259}
|
||||||
m_LocalScale: {x: 15, y: 15, z: 15}
|
m_LocalScale: {x: 15, y: 15, z: 15}
|
||||||
m_Children: []
|
m_Children: []
|
||||||
m_Father: {fileID: 0}
|
m_Father: {fileID: 0}
|
||||||
@@ -564,7 +564,7 @@ Transform:
|
|||||||
m_PrefabAsset: {fileID: 0}
|
m_PrefabAsset: {fileID: 0}
|
||||||
m_GameObject: {fileID: 1549583588}
|
m_GameObject: {fileID: 1549583588}
|
||||||
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
|
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
|
||||||
m_LocalPosition: {x: -3.4, y: 15.5, z: -8.24259}
|
m_LocalPosition: {x: -3.4, y: 14, z: -8.24259}
|
||||||
m_LocalScale: {x: 15, y: 15, z: 15}
|
m_LocalScale: {x: 15, y: 15, z: 15}
|
||||||
m_Children: []
|
m_Children: []
|
||||||
m_Father: {fileID: 0}
|
m_Father: {fileID: 0}
|
||||||
@@ -2126,7 +2126,7 @@ BoxCollider:
|
|||||||
m_IsTrigger: 0
|
m_IsTrigger: 0
|
||||||
m_Enabled: 1
|
m_Enabled: 1
|
||||||
serializedVersion: 2
|
serializedVersion: 2
|
||||||
m_Size: {x: 2.0000012, y: 2, z: 2.0000002}
|
m_Size: {x: 2, y: 2, z: 2}
|
||||||
m_Center: {x: 0, y: -0.0000000037252903, z: 0}
|
m_Center: {x: 0, y: -0.0000000037252903, z: 0}
|
||||||
--- !u!54 &6172235275449449131
|
--- !u!54 &6172235275449449131
|
||||||
Rigidbody:
|
Rigidbody:
|
||||||
|
|||||||
34
3D/Assets/Scripts/TankAudio.cs
Normal file
34
3D/Assets/Scripts/TankAudio.cs
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
using System.Collections;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using UnityEngine;
|
||||||
|
|
||||||
|
public class TankAudio : MonoBehaviour
|
||||||
|
{
|
||||||
|
public AudioSource m_MovementAudio;
|
||||||
|
public AudioClip m_EngineIdle;
|
||||||
|
public AudioClip m_EngineDrive;
|
||||||
|
public TankMovement tankMovement;
|
||||||
|
public float m_PitchRange = 0.2f;
|
||||||
|
private float m_OriginalPitch;
|
||||||
|
|
||||||
|
private void Start() {
|
||||||
|
m_OriginalPitch = m_MovementAudio.pitch;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void EngineAudio() {
|
||||||
|
//for audio playing
|
||||||
|
if(Mathf.Abs(m_MovementInputValue) < 0.1f && Mathf.Abs(m_TurnInputValue) < 0.1f) { //if tank is not moving
|
||||||
|
if(m_MovementAudio.clip == m_EngineDrive) {
|
||||||
|
m_MovementAudio.clip = m_EngineIdle;
|
||||||
|
m_MovementAudio.pitch = Random.Range(m_OriginalPitch - m_PitchRange, m_OriginalPitch + m_PitchRange);
|
||||||
|
m_MovementAudio.Play();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (m_MovementAudio.clip == m_EngineIdle) {
|
||||||
|
m_MovementAudio.clip = m_EngineDrive;
|
||||||
|
m_MovementAudio.pitch = Random.Range(m_OriginalPitch - m_PitchRange, m_OriginalPitch + m_PitchRange);
|
||||||
|
m_MovementAudio.Play();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
11
3D/Assets/Scripts/TankAudio.cs.meta
Normal file
11
3D/Assets/Scripts/TankAudio.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: f04c0702d9c4a094b8e0a95e451f81eb
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@@ -5,19 +5,17 @@ public class TankMovement : MonoBehaviour
|
|||||||
{
|
{
|
||||||
public int m_PlayerNumber = 1;
|
public int m_PlayerNumber = 1;
|
||||||
public float m_Speed = 30f;
|
public float m_Speed = 30f;
|
||||||
public float m_TurnSpeed = 180f;
|
public float m_TurnSpeed = 180f;
|
||||||
public float m_PitchRange = 0.2f;
|
|
||||||
/*public AudioSource m_MovementAudio;
|
|
||||||
public AudioClip m_EngineIdle;
|
|
||||||
public AudioClip m_EngineDrive;*/
|
|
||||||
|
|
||||||
private string m_MovementAxisName;
|
private string m_MovementAxisName;
|
||||||
private string m_TurnAxisName;
|
private string m_TurnAxisName;
|
||||||
private float m_MovementInputValue;
|
protected float m_MovementInputValue;
|
||||||
private float m_TurnInputValue;
|
private float m_TurnInputValue;
|
||||||
private float m_OriginalPitch;
|
|
||||||
private Rigidbody m_Rigidbody;
|
private Rigidbody m_Rigidbody;
|
||||||
|
|
||||||
|
//TODO: Getter setter for the audio variables
|
||||||
|
//and try out character controller
|
||||||
|
|
||||||
private void Awake() {
|
private void Awake() {
|
||||||
m_Rigidbody = GetComponent<Rigidbody>();
|
m_Rigidbody = GetComponent<Rigidbody>();
|
||||||
}
|
}
|
||||||
@@ -34,33 +32,14 @@ public class TankMovement : MonoBehaviour
|
|||||||
|
|
||||||
private void Start() {
|
private void Start() {
|
||||||
m_MovementAxisName = "Vertical" + m_PlayerNumber; //different virtual axis for different players
|
m_MovementAxisName = "Vertical" + m_PlayerNumber; //different virtual axis for different players
|
||||||
m_TurnAxisName = "Horizontal" + m_PlayerNumber;
|
m_TurnAxisName = "Horizontal" + m_PlayerNumber;
|
||||||
//m_OriginalPitch = m_MovementAudio.pitch;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void Update() {
|
private void Update() {
|
||||||
//Getting input
|
//Getting input
|
||||||
m_MovementInputValue = Input.GetAxisRaw(m_MovementAxisName);
|
m_MovementInputValue = Input.GetAxisRaw(m_MovementAxisName);
|
||||||
m_TurnInputValue = Input.GetAxisRaw(m_TurnAxisName);
|
m_TurnInputValue = Input.GetAxisRaw(m_TurnAxisName);
|
||||||
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/*private void EngineAudio() {
|
|
||||||
//for audio playing
|
|
||||||
if(Mathf.Abs(m_MovementInputValue) < 0.1f && Mathf.Abs(m_TurnInputValue) < 0.1f) { //if tank is not moving
|
|
||||||
if(m_MovementAudio.clip == m_EngineDrive) {
|
|
||||||
m_MovementAudio.clip = m_EngineIdle;
|
|
||||||
m_MovementAudio.pitch = Random.Range(m_OriginalPitch - m_PitchRange, m_OriginalPitch + m_PitchRange);
|
|
||||||
m_MovementAudio.Play();
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if (m_MovementAudio.clip == m_EngineIdle) {
|
|
||||||
m_MovementAudio.clip = m_EngineDrive;
|
|
||||||
m_MovementAudio.pitch = Random.Range(m_OriginalPitch - m_PitchRange, m_OriginalPitch + m_PitchRange);
|
|
||||||
m_MovementAudio.Play();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}*/
|
|
||||||
|
|
||||||
private void FixedUpdate() {
|
private void FixedUpdate() {
|
||||||
//Moving the tank
|
//Moving the tank
|
||||||
|
|||||||
Reference in New Issue
Block a user