I am making an FPS game and I set my gun to do 25 damage and the player’s health is 100 but when I shoot another player it instantly kills them.
This is my player health script:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Photon.Pun;
using TMPro;
public class Health : MonoBehaviour
{
public int health;
[Header("UI")]
public TextMeshProUGUI healthText;
[PunRPC]
public void TakeDamage(int _damage)
{
health -= _damage;
healthText.text = health.ToString();
if (health <= 0)
{
Destroy(gameObject);
}
}
}
And this is my weapon script:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Photon.Pun;
public class Weapon : MonoBehaviour
{
public int damage;
public Camera camera;
public float fireRate;
[Header("VFX")]
public GameObject hitVFX;
private float nextFire;
// Update is called once per frame
void Update()
{
if (nextFire > 0)
nextFire -= Time.deltaTime;
if (Input.GetButton("Fire1") && nextFire <= 0)
{
Fire();
}
}
void Fire()
{
Ray ray = new Ray(camera.transform.position, camera.transform.forward);
RaycastHit hit;
if (Physics.Raycast(ray.origin, ray.direction, out hit, 100f))
{
PhotonNetwork.Instantiate(hitVFX.name, hit.point, Quaternion.identity);
if (hit.transform.gameObject.GetComponent<Health>())
{
hit.transform.gameObject.GetComponent<PhotonView>().RPC("TakeDamage", RpcTarget.All, damage);
}
}
}
}
I don’t know how to fix this problem.