- Home /
Photon - Change others player health problem
That's my bullet script, i'm trying to get the reached player PhotonView, then i get their PlayerController script and change their health, but it don't seem to work, anyone can help?
void Start () {
pv = PhotonView.Get(this);
rayAim = Camera.mainCamera.ScreenPointToRay(new Vector3(Screen.width/2, Screen.height/2, 0));
Vector3 directionShot = transform.TransformDirection(Vector3.forward);
if(Physics.Raycast(rayAim, out hit, range)){
if(hit.collider.tag == "Player") {
pv.RPC ("HitEnemyLife", PhotonPlayer.Find(hit.collider.gameObject.GetComponent<PhotonView>().viewID));
}
}
[RPC]
void HitEnemyLife() {
hit.collider.gameObject.GetComponent<PlayerController>().hp -= 10;
}
Comment
I'm not sure, but I think the problem is you are trying to access the variable hit
outside the function in which it is declared. Perhaps void HitEnemyLife
should have a parameter?
void HitEnemyLife(RayCastHit hit) {
}
I don't know the implementation with Photon though :/