add fight sounds

This commit is contained in:
chyknkat
2020-02-02 10:35:28 -05:00
parent a87e8ff093
commit da15566f31
14 changed files with 164 additions and 7 deletions

Binary file not shown.

View File

@@ -0,0 +1,22 @@
fileFormatVersion: 2
guid: 969fb43c02f3e464c8e0907e44dc946c
AudioImporter:
externalObjects: {}
serializedVersion: 6
defaultSettings:
loadType: 0
sampleRateSetting: 0
sampleRateOverride: 44100
compressionFormat: 1
quality: 1
conversionMode: 0
platformSettingOverrides: {}
forceToMono: 0
normalize: 1
preloadAudioData: 1
loadInBackground: 0
ambisonic: 0
3D: 1
userData:
assetBundleName:
assetBundleVariant:

Binary file not shown.

View File

@@ -0,0 +1,22 @@
fileFormatVersion: 2
guid: 3095e099213c73c4182d9feeae77ebbd
AudioImporter:
externalObjects: {}
serializedVersion: 6
defaultSettings:
loadType: 0
sampleRateSetting: 0
sampleRateOverride: 44100
compressionFormat: 1
quality: 1
conversionMode: 0
platformSettingOverrides: {}
forceToMono: 0
normalize: 1
preloadAudioData: 1
loadInBackground: 0
ambisonic: 0
3D: 1
userData:
assetBundleName:
assetBundleVariant:

Binary file not shown.

View File

@@ -0,0 +1,22 @@
fileFormatVersion: 2
guid: 292f0e8e04642864daaf315efade99c7
AudioImporter:
externalObjects: {}
serializedVersion: 6
defaultSettings:
loadType: 0
sampleRateSetting: 0
sampleRateOverride: 44100
compressionFormat: 1
quality: 1
conversionMode: 0
platformSettingOverrides: {}
forceToMono: 0
normalize: 1
preloadAudioData: 1
loadInBackground: 0
ambisonic: 0
3D: 1
userData:
assetBundleName:
assetBundleVariant:

Binary file not shown.

View File

@@ -0,0 +1,22 @@
fileFormatVersion: 2
guid: 33e618f5ded88f7449cf8c6b88e71c8f
AudioImporter:
externalObjects: {}
serializedVersion: 6
defaultSettings:
loadType: 0
sampleRateSetting: 0
sampleRateOverride: 44100
compressionFormat: 1
quality: 1
conversionMode: 0
platformSettingOverrides: {}
forceToMono: 0
normalize: 1
preloadAudioData: 1
loadInBackground: 0
ambisonic: 0
3D: 1
userData:
assetBundleName:
assetBundleVariant:

Binary file not shown.

View File

@@ -0,0 +1,22 @@
fileFormatVersion: 2
guid: aafb1c137c5574744b6c2c5b7d5e7055
AudioImporter:
externalObjects: {}
serializedVersion: 6
defaultSettings:
loadType: 0
sampleRateSetting: 0
sampleRateOverride: 44100
compressionFormat: 1
quality: 1
conversionMode: 0
platformSettingOverrides: {}
forceToMono: 0
normalize: 1
preloadAudioData: 1
loadInBackground: 0
ambisonic: 0
3D: 1
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -47232,7 +47232,7 @@ Transform:
m_PrefabAsset: {fileID: 0} m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1671840916} m_GameObject: {fileID: 1671840916}
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1} m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
m_LocalPosition: {x: -5, y: -2, z: 0} m_LocalPosition: {x: 45.5, y: 35.5, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1} m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: [] m_Children: []
m_Father: {fileID: 1008122163} m_Father: {fileID: 1008122163}
@@ -90341,12 +90341,12 @@ PrefabInstance:
- target: {fileID: 8554420466772133694, guid: f859e1c9214db2c4eaaeff51febb3222, - target: {fileID: 8554420466772133694, guid: f859e1c9214db2c4eaaeff51febb3222,
type: 3} type: 3}
propertyPath: m_LocalPosition.x propertyPath: m_LocalPosition.x
value: 42.01 value: 54.1
objectReference: {fileID: 0} objectReference: {fileID: 0}
- target: {fileID: 8554420466772133694, guid: f859e1c9214db2c4eaaeff51febb3222, - target: {fileID: 8554420466772133694, guid: f859e1c9214db2c4eaaeff51febb3222,
type: 3} type: 3}
propertyPath: m_LocalPosition.y propertyPath: m_LocalPosition.y
value: 22.76 value: 32.6
objectReference: {fileID: 0} objectReference: {fileID: 0}
- target: {fileID: 8554420466772133694, guid: f859e1c9214db2c4eaaeff51febb3222, - target: {fileID: 8554420466772133694, guid: f859e1c9214db2c4eaaeff51febb3222,
type: 3} type: 3}

View File

@@ -228,7 +228,7 @@ public class EventControls : MonoBehaviour
// var offset = camera.transform.position.x - (int)camera.transform.position.x; // var offset = camera.transform.position.x - (int)camera.transform.position.x;
// transform.position = new Vector3(transform.position.x + offset, transform.position.y, 0); // transform.position = new Vector3(transform.position.x + offset, transform.position.y, 0);
//} //}
private EventControlTile GenerateEventControlTile(Vector3Int position) private EventControlTile GenerateEventControlTile(Vector3Int position)
{ {
var randomNumber = Random.Range(0, TileToKeyMappings.TileToKey.Count); var randomNumber = Random.Range(0, TileToKeyMappings.TileToKey.Count);

View File

@@ -30,6 +30,8 @@ public class Player : MonoBehaviour
private bool isMovementEnabled = true; private bool isMovementEnabled = true;
private bool isFighting = false; private bool isFighting = false;
private bool isPlayerHurt = false;
private void Start() private void Start()
{ {
rigidBody = GetComponent<Rigidbody2D>(); rigidBody = GetComponent<Rigidbody2D>();
@@ -73,6 +75,7 @@ public class Player : MonoBehaviour
if (coll.gameObject.tag == "Pizza") if (coll.gameObject.tag == "Pizza")
{ {
Destroy(coll.gameObject); Destroy(coll.gameObject);
SoundManagerScript.PlaySound("eat");
currentHealth += currentHealth < startHealth ? 1 : 0; currentHealth += currentHealth < startHealth ? 1 : 0;
healthBar.size = new Vector2(1.5f * currentHealth, this.healthBar.size.y); healthBar.size = new Vector2(1.5f * currentHealth, this.healthBar.size.y);
} }
@@ -111,7 +114,7 @@ public class Player : MonoBehaviour
Run(); Run();
FlipSprite(); FlipSprite();
} }
PlayFightSound();
HandleAnimations(); HandleAnimations();
} }
@@ -216,20 +219,38 @@ public class Player : MonoBehaviour
animator.SetBool("IsFighting", isFighting); animator.SetBool("IsFighting", isFighting);
} }
private void PlayFightSound()
{
if (isFighting && !isPlayerHurt)
{
SoundManagerScript.PlaySound(GetRandomFightClipName());
}
}
private string GetRandomFightClipName()
{
var fightClipNames = new List<string> { "punch", "hard punch", "slap", "hard slap" };
var randomNumber = UnityEngine.Random.Range(0, fightClipNames.Count);
return fightClipNames[randomNumber];
}
public void StartEncounter() public void StartEncounter()
{ {
isPlayerHurt = false;
isFighting = true; isFighting = true;
isMovementEnabled = false; isMovementEnabled = false;
} }
public void EndEncounter() public void EndEncounter()
{ {
isPlayerHurt = false;
isFighting = false; isFighting = false;
isMovementEnabled = true; isMovementEnabled = true;
} }
public void ThrowUserInTheAirHurt() public void ThrowUserInTheAirHurt()
{ {
isPlayerHurt = true;
GetComponent<Rigidbody2D>().velocity += new Vector2(Mathf.Sign(transform.localScale.x) * -1 * hurtVelocity, hurtVelocity); GetComponent<Rigidbody2D>().velocity += new Vector2(Mathf.Sign(transform.localScale.x) * -1 * hurtVelocity, hurtVelocity);
} }
} }

View File

@@ -5,7 +5,9 @@ using UnityEngine;
public class SoundManagerScript : MonoBehaviour public class SoundManagerScript : MonoBehaviour
{ {
public static AudioClip jumpSound, screamSound, wrongButtonSound, bugLaughSound, drinkSound; public static AudioClip jumpSound, screamSound, wrongButtonSound,
bugLaughSound, drinkSound, eatSound, punchSound, hardPunchSound,
slapSound, hardSlapSound, winSound;
static AudioSource audioSrc; static AudioSource audioSrc;
// Start is called before the first frame update // Start is called before the first frame update
@@ -16,6 +18,11 @@ public class SoundManagerScript : MonoBehaviour
wrongButtonSound = Resources.Load<AudioClip>("Audio/WrongButton"); wrongButtonSound = Resources.Load<AudioClip>("Audio/WrongButton");
bugLaughSound = Resources.Load<AudioClip>("Audio/BugLaugh"); bugLaughSound = Resources.Load<AudioClip>("Audio/BugLaugh");
drinkSound = Resources.Load<AudioClip>("Audio/Drink"); drinkSound = Resources.Load<AudioClip>("Audio/Drink");
eatSound = Resources.Load<AudioClip>("Audio/Eat");
punchSound = Resources.Load<AudioClip>("Audio/Punch");
hardPunchSound = Resources.Load<AudioClip>("Audio/HardPunch");
slapSound = Resources.Load<AudioClip>("Audio/Slap");
hardSlapSound = Resources.Load<AudioClip>("Audio/HardSlap");
audioSrc = GetComponent<AudioSource>(); audioSrc = GetComponent<AudioSource>();
} }
@@ -45,6 +52,25 @@ public class SoundManagerScript : MonoBehaviour
case "drink": case "drink":
audioSrc.PlayOneShot(drinkSound); audioSrc.PlayOneShot(drinkSound);
break; break;
case "eat":
audioSrc.PlayOneShot(eatSound);
break;
case "punch":
audioSrc.PlayOneShot(punchSound);
break;
case "hard punch":
audioSrc.PlayOneShot(hardPunchSound);
break;
case "slap":
audioSrc.PlayOneShot(slapSound);
break;
case "hard slap":
audioSrc.PlayOneShot(hardSlapSound);
break;
case "win":
audioSrc.PlayOneShot(winSound);
break;
} }
} }
} }