Question by
Wesley21spelde · Jan 14, 2016 at 09:47 PM ·
rpcdamageapply
RPC Not working
Hey guys i tried to get this working but failed Yes thare is a Photonview on the Enemy Health Object Observing the EnemyHealth Schript
i tried gameObject.GetComponent
i tried pv.GetComponent
i tried PhotonView pv.GetComponent
i tried collision.GetComponent
using UnityEngine;
using System.Collections;
using System;
public class EnemyHealth : MonoBehaviour
{
public int maxHealth = 100;
public int curHealth = 100;
void Start()
{
//dh = GameObject.Find("HealthBar").GetComponent<DisplayHealth>();
}
void OnGUI()
{
// GUI.Box(new Rect(10, 40, healthBarLength, 20), curHealth + "/" + maxHealth);
}
[PunRPC]
void OnCollisionEnter(Collision collision)
{
if (collision.gameObject.tag == "Bullet")
{
PhotonView pv = GetComponent<PhotonView>();
if (pv == null)
{
Debug.LogError("Freak Out!");
}
else
{
AddjustCurrentHealth(-10); //i tried to get this working with the code but failed!
//THIS CODE//
// --> // GetComponent<PhotonView>();.RPC("AddjustCurrentHealth", PhotonTargets.All, AddjustCurrentHealth); <-- //
}
}
}
[PunRPC]
public void AddjustCurrentHealth(int adj)
{
curHealth += adj;
if (curHealth < 0)
curHealth = 0;
if (curHealth > maxHealth)
curHealth = maxHealth;
if (maxHealth < 1)
maxHealth = 1;
if (curHealth < 10)
Die();
// healthBarLength = (Screen.width / 2) * (curHealth / (float)maxHealth);
}
[PunRPC]
void Die()
{
Destroy(gameObject);
}
}
Comment