- Home /
Photon Cloud, Multiplayer Damage script
I posted a question a while ago about a damage script and thought I had fixed it but I have now got a new error I am pretty new to both unity and photon and I am baffled by this problem.
I created a damage script;
using UnityEngine;
using System.Collections;
public class CombatScript: Photon.MonoBehaviour {
public int hp = 1;
void ApplyDamage(int Damage)
{
hp -= (int)Damage;
if (hp <= 0)
{
}
else
{
photonView.RPC("setHP", PhotonTargets.Others, hp);
}
}
public void UpdateHP(int hitPoints)
{
hp = hitPoints;
}
void Update ()
{
DontDestroyOnLoad(this);
if(hp <= 0)
{
Debug.Log(photonView.viewID + " is DEAD! ");
}
}
[RPC]
void setHP(int newHP)
{
hp = newHP;
}
}
The updatehp is called in a different script i use for character stats.
Now when i run both the editor version and the compiled version the editor is the only one that can deal damage, and also takes damage when attacking and is the only one that dies, while the compiled version gives this error;
PhotonView with ID 1001 has no method "setHP" marked with the [RPC](C#) or @RPC(JS) Property! Args: int32
I think the problem is code i use to instantiate the character plus scripts as only the editor version seems to be the only one to the damage/combat script instantiated Here is the code i use to instantiate the character
GameObject player = PhotonNetwork.Instantiate("PlayerLightSanguine", Vector3.zero, Quaternion.identity, 0);
player.AddComponent<ThirdPersonCamera>();
player.AddComponent<ThirdPersonController>();
player.AddComponent<DontDestroyScript>();
player.AddComponent<CombatScript>();
Camera.main.gameObject.AddComponent<SmoothFollow>().target = player.transform;
Camera.main.gameObject.AddComponent<SmoothLookAt>().target = player.transform;
Camera.main.gameObject.AddComponent<MouseOrbit>().target = player.transform;
The DontDestroyScript is just so it doesn't destroy on loading a new scene.
Your answer
Follow this Question
Related Questions
How to instatiate two players simultaneoulsy before loading level 1 Answer
Unity Photon Network - Text Mesh Sync 1 Answer
Unity3D Photon movement synchronization 0 Answers
Updating multiplayer map on joining 1 Answer
Photon timer issue 2 Answers