- Home /
[Photon] Cant give damage to other client and getting RPC error.
All codes are fine but I dont know why Im getting this error. So if you know something about this then please help me out! Im very grateful of you if you help me Here is health Script using UnityEngine; using System.Collections;
public class Health : MonoBehaviour {
public float hitPoints = 100f;
float currentHitPoints;
public Transform deadReplacement;
bool isDead = false;
// Use this for initialization
void Start () {
currentHitPoints = hitPoints;
}
[RPC]
public void TakeDamage(float amt) {
currentHitPoints -= amt;
if(currentHitPoints <= 0) {
Die();
}
}
/*void OnGUI() {
if( GetComponent<PhotonView>().isMine && gameObject.tag == "Player" ) {
if( GUI.Button(new Rect (Screen.width-100, 0, 100, 40), "Suicide!") ) {
Die ();
}
}
}*/
[RPC]
public void Die() {
if( GetComponent<PhotonView>().instantiationId==0 ) {
if (isDead)
return;
isDead = true;
if (deadReplacement) {
PhotonNetwork.Instantiate(this.deadReplacement.name, transform.position, Quaternion.identity, 0);
PhotonNetwork.Destroy(gameObject);
PhotonNetwork.Disconnect();
Application.LoadLevel(0);
}
}
}
}
Here is part of gun script (raycasting)
public float minDamage;
public float maxDamage;
if (Physics.Raycast(ray, out hitInfo, range, thingsPlayerCanHit))
{
if (hitInfo.transform.gameObject.collider.tag == "Player") {
hitInfo.transform.gameObject.GetComponent<PhotonView> ().RPC ("TakeDamage", PhotonTargets.AllBuffered, Random.Range(minDamage, maxDamage));
}
error is:
PhotonView with ID 1001 has no method "TakeDamage" marked with the [RPC](C#) or @RPC(JS) Property! Args: int32
Also i wanna instantiate a ragdoll when player dies and destroy it too! See in health script. Thats all! Thanks for help in advance!
Hi,
the RPC function needs to be implemented in the same class from where it is called. I'm currently not sure if this is the case here. If it is, you are fine in terms of this possible issue. The Die
function does not require the [PunRPC] attribute header because it is not called as RPC (as far as I can see it is called directly). Destroying a networked object should only be done by the owner of the object, so you should surround this call with a photonView.is$$anonymous$$ine
condition. I'm also not sure if the PhotonNetwork.Instantiate
and the PhotonNetwork.Destroy
calls are actually executed because you call PhotonNetwork.Disconnect
directly after those other calls. To make sure that those messages are actually sent, add PhotonNetwork.SendOutgoingCommands
before disconnecting from Photon.
Your answer
Follow this Question
Related Questions
Networking: Keep room alive without active players 0 Answers
Photon - How to spawn enemies that don't have a PhotonView and be synced with other clients 1 Answer
How many current players will I get daily if I have 10k installs 1 Answer
Synchronize multiple spawnpoints (Photon + RCC) 0 Answers
RPC to certain player in room using their nickname/userID 0 Answers