Post by komposite on Mar 16, 2020 14:20:56 GMT
Hello all !
I'm working on my audio integration of Invector (via Wwise), and I need to get what type of damage has been deal to the player, but also, if the player is protecting, and the cherry on the cake would be to have tag of what the player has hit.
My logic here is :
Using the unity event on receive damage, i'll check what type of damage is dealt (sword, axe, spike, etc...) and select the right sound accordingly.
But if my player is blocking the damage, i'll play a different sound (if the player can block this attack, of course...)
Here's what I wrote so far :
Here's what I wrote so far :
(note that I'm using animations event to play sounds via wwise)
using Invector.vCharacterController;
using Invector;
using UnityEngine;
public class player_wwise_events : vMonoBehaviour
{
//Get the player and enable debug
public GameObject Player;
public bool DebugEnable = false;
//name for the sprint switch
public string Sprint;
public string isSprinting;
public string isWalking;
// name of the sprint RTPC
public string SpeedRTPC;
// name of the damage event
public string takedamage;
// name of the death event
public string playerdies;
private bool hastheplayerdied;
// name of the damage switch
public string DamagePlayerSwitch;
// string to get what kind of damage you took
private string typeofdamage;
// name of the switch you've hit
public string HitPlayerSwitch;
// string of the tag you've hit
private string typeofhit;
// name of the protection switch
public string PlayerProtectionSwitch;
// bool if the player is in protection
private bool PlayerProtection;
// Start is called before the first frame update
void Start()
{
//register emitter for wwise
AkSoundEngine.RegisterGameObj(gameObject);
//the player is alive
hastheplayerdied = false;
}
void Update()
{
// send player speed to speedRTPC (reading speed from the rigidbody info
AkSoundEngine.SetRTPCValue(SpeedRTPC, Player.GetComponent<Rigidbody>().velocity.magnitude, gameObject);
//Check if the chara is playing
if (Player.GetComponent<vThirdPersonController>().isSprinting)
{
SetSprintSwitch();
}
else
{
UnsetSprintSwitch();
}
if (Player.GetComponent<vThirdPersonController>().currentHealth <= 0 && !hastheplayerdied)
{
PlayerisDead();
}
//DEBUG
if (DebugEnable)
{
Debug.Log(Player.GetComponent<Rigidbody>().velocity.magnitude);
}
// get the type of damage the chara has received
typeofdamage = Player.GetComponent<Invector.vMelee.vHitInfo>().attackObject.damage.damageType;
// change type of damage the chara has received
AkSoundEngine.SetSwitch(DamagePlayerSwitch, typeofdamage, gameObject);
//DEBUG
if (DebugEnable)
print(typeofdamage);
// get the tag the player has hit
typeofhit = GetComponent<Invector.vMelee.vHitInfo>().targetCollider.tag;
if (DebugEnable)
print(typeofhit);
// change the type of what the player has hit
AkSoundEngine.SetSwitch(HitPlayerSwitch, typeofhit, gameObject);
//check if the player is protecting
//PlayerProtection = can't find where the isblocking is...
}
// method to use animation event to call wwise event
void PlayWwiseEvent(string nomdelevent)
{
AkSoundEngine.PostEvent(nomdelevent, gameObject);
//DEBUG
if (DebugEnable)
{ Debug.Log("Je joue l'event" + nomdelevent); }
}
// method to call damage
public void PlayDamage()
{
AkSoundEngine.PostEvent(takedamage, gameObject);
}
// set is sprinting switch
void SetSprintSwitch()
{
AkSoundEngine.SetSwitch(Sprint, isSprinting, gameObject);
//DEBUG
if (DebugEnable)
{
Debug.Log("Is Sprinting");
}
}
// unset is sprinting switch
void UnsetSprintSwitch()
{
AkSoundEngine.SetSwitch(Sprint, isWalking, gameObject);
//DEBUG
if (DebugEnable)
{
Debug.Log("Is Not Sprinting");
}
}
//check if player is dead
public void PlayerisDead()
{
hastheplayerdied = true;
AkSoundEngine.PostEvent(playerdies, gameObject);
//DEBUG
if (DebugEnable)
{
Debug.Log("player has died");
}
}
}
But this is giving me this error :
ArgumentException: GetComponent requires that the requested component 'vHitInfo' derives from MonoBehaviour or Component or is an interface.
UnityEngine.GameObject.GetComponent[T] () (at /Users/builduser/buildslave/unity/build/Runtime/Export/GameObject.bindings.cs:28)
player_wwise_events.Update () (at Assets/SCRIPTS/player_wwise_events.cs:100)
I get that vHitInfo is not a monobehaviour script, but I don't know how to work my way around that.
any help is appreciated !
Thanks ! 🙏