Im trying to program shooting and have done this multiple times by now, however this time Unity is nto feeling it and returns the z axis when casting a ray.
void Update()
{
if(isLocalPlayer)
{
if(Input.GetKeyDown(KeyCode.Mouse0))
{
Shoot(transform.forward);
}
}
}
[Command]
void Shoot(Vector dir)
{
DamagePlayer(dir);
}
[ClientRpc]
void DamagePlayer(Vector3 dir)
{
RaycastHit hit;
if (Physics.Raycast(transform.position, dir, out hit))
{
if (hit.transform.gameObject.tag == "Player")
{
hit.transform.GetComponent<Player>().health -= 10;
}
}
}