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

View File

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

View File

@@ -30,6 +30,8 @@ public class Player : MonoBehaviour
private bool isMovementEnabled = true;
private bool isFighting = false;
private bool isPlayerHurt = false;
private void Start()
{
rigidBody = GetComponent<Rigidbody2D>();
@@ -73,6 +75,7 @@ public class Player : MonoBehaviour
if (coll.gameObject.tag == "Pizza")
{
Destroy(coll.gameObject);
SoundManagerScript.PlaySound("eat");
currentHealth += currentHealth < startHealth ? 1 : 0;
healthBar.size = new Vector2(1.5f * currentHealth, this.healthBar.size.y);
}
@@ -111,7 +114,7 @@ public class Player : MonoBehaviour
Run();
FlipSprite();
}
PlayFightSound();
HandleAnimations();
}
@@ -216,20 +219,38 @@ public class Player : MonoBehaviour
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()
{
isPlayerHurt = false;
isFighting = true;
isMovementEnabled = false;
}
public void EndEncounter()
{
isPlayerHurt = false;
isFighting = false;
isMovementEnabled = true;
}
public void ThrowUserInTheAirHurt()
{
{
isPlayerHurt = true;
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 static AudioClip jumpSound, screamSound, wrongButtonSound, bugLaughSound, drinkSound;
public static AudioClip jumpSound, screamSound, wrongButtonSound,
bugLaughSound, drinkSound, eatSound, punchSound, hardPunchSound,
slapSound, hardSlapSound, winSound;
static AudioSource audioSrc;
// Start is called before the first frame update
@@ -16,6 +18,11 @@ public class SoundManagerScript : MonoBehaviour
wrongButtonSound = Resources.Load<AudioClip>("Audio/WrongButton");
bugLaughSound = Resources.Load<AudioClip>("Audio/BugLaugh");
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>();
}
@@ -45,6 +52,25 @@ public class SoundManagerScript : MonoBehaviour
case "drink":
audioSrc.PlayOneShot(drinkSound);
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;
}
}
}