cannot reference parent network identity.netId when applying damage
Hello friends!
I'm looking to implement a custom hitbox detection system into my networked uNet FPS. I'm currently testing this on a networked bot player. I have a cube with mesh renderer disabled where the bots head should be, and layered the cube "Player Head". On the cube there's a networked script called Hitbox_Head, which has a reference to the bot's parent object's network identity.
Here's the line of code that's throwing a no object reference error
hit.transform.GetComponent<Hitbox_Head>().CmdApplyDamageOnServer(hit.transform.GetComponent<Hitbox_Head>().playerID, 100);
The debugging log is telling me the playerID variable indeed correctly outputs the players netID into console, however throwing exceptions when using this command.
Command:
[Command]
public void CmdApplyDamageOnServer(NetworkInstanceId networkID, int DamageAmount)
{
GameObject hitPlayerGo = NetworkServer.FindLocalObject(networkID);
hitPlayerGo.GetComponent<Player_Health>().DeductHealth(DamageAmount);
}
Answer by lbryan212 · Jul 23, 2019 at 11:42 AM
I put this under my raycast function and everything started working. Just in-case anyone else has similar problem.
NetworkIdentity playerIdentity = hit.transform.GetComponentInParent<NetworkIdentity>();
if (hit.transform.CompareTag("Bot"))
{
CmdApplyDamageOnServerBot(playerIdentity.netId, 100);
Quaternion hitAngle2 = Quaternion.LookRotation(hit.normal);
CmdSpawnBloodPrefab(hit.point, hitAngle2, 5);
// Debug.Log("The ray hit the players head" + playerIdentity.netId);
}
Your answer
Follow this Question
Related Questions
Help with selecting objects through raycast in multiplayer game 0 Answers
Raycast Hit on a Server Object? 0 Answers
How do i deal damage with raycasts in UNET? 0 Answers
Network ray returns different mouse positions 1 Answer
Cant run command on client? 0 Answers