I’m toward the end of the Combat course in the RPG bundle, in the final polish section where I’ve overhauled my models. Something’s gone wrong on my player prefab, though, because now when I play the game and attack someone, it says:
Can not play a disabled audio source
UnityEngine.Events.UnityEvent:Invoke ()
RPG.Combat.Weapon:OnHit () (at Assets/Scripts/Combat/Weapon.cs:13)
RPG.Combat.Fighter:Hit () (at Assets/Scripts/Combat/Fighter.cs:86)
–
Here is a screenshot of my Equipped Unarmed prefab, although this is happening no matter which weapon I equip.
The weird thing is, this is only affecting my player. The Archer prefab and a wolf prefab all make their attack and damage/die sounds properly. They all derive from the same character prefab. I even tried deleting my Player prefab and recreating it as a fresh variant of the Character prefab, but the same thing occurs.
The sound that originates from the Fighter when you hit should be from the attached weapon. For example, if you have a sword, all of the sword sounds should originate from an AudioSource on the sword itself. (Same with the bow, or the unarmed). This should respond to when Fighter calls the Weapon’s OnHit() method, which invokes the Weapon’s OnHit UnityEvent.
The sound that the character makes when they are hit should be on the DamageSFX. You’ll link that sound up with the Character’s Health.TakeDamage Unity Event.
The sound that the character makes when they die should be on the DieFX, which will be linked up to the character’s Health.OnDeath UnityEvent.
Yes, I’m aware. It was working perfectly yesterday. Further, it is still working on the enemies, so the code likely isn’t the culprit. Here’s a shot of my TakeDamage code, my Health script in the Inspector, and shots of my DamageSFX game objects.
It’s also not having a problem updating and displaying my damage text over the player’s head.
UPDATE: I’ve narrowed the problem down! It is only projectiles that are failing to trigger the Take Damage SFX. If the player uses a Bow or Fireball, the enemy does not grunt when hit(but does cry when killed). If the player is attacked by a Bow, she has the exact same behavior. But if the attack is Unarmed or Sword, the hit grunt SFX plays accurately!
So this looks correct. The character should be generating the grunt sound effect when he or she or it gets hit, regardless of the damage source unless the character is killed outright, in which case they should only be gasping in death…
It occurs to me, you may not be hearing the gasp because the sound is being attentuated (3d sound means the further from the source of the sound you are, the quieter (or even so quiet you can’t hear it), the sound will be.
So, you pointed me in the right direction. It wasn’t that the sound was too far away(like I said, I could hear it fine when the weapon I was being attacked with was a sword, so the player was the exact same distance from the boom mic as when being attacked with a bow). But actually, the hit sound of the arrow and the fireball were both so loud that I couldn’t hear the grunt. I turned their volume down to half and I was able to hear the grunts!