- Home /
Question by
Wesley21spelde · Jan 26, 2016 at 12:29 PM ·
scripting problemrpcdamagehealth
Addjustcurrenthealth not working
Hey guys i cant get this working my addjustcurrenthealth in the rpc function does nothing to my Enemy health script
does some one know how this is done ?
addjust the health when its hit by this bullet so in my other clients it also got the damage and yes both have a photonview on them
using UnityEngine; using System.Collections; using System;
public class Bullet3 : MonoBehaviour
{
public float curHealth = 10.0f;
[PunRPC]
public void OnCollisionEnter(Collision col)
{
if (col.transform.tag == "Enemy")
{
var pv = col.transform.GetComponent<PhotonView>();
if (pv == null)
{
Debug.LogError("Freak Out!");
}
else
{
pv.photonView.RPC("AddjustCurrentHealth", RPCMode.All, curHealth);
}
}
}
using UnityEngine; using System.Collections; using System;
public class EnemyHealth : MonoBehaviour
{
public new PhotonView photonView;
public int maxHealth = 100;
public int curHealth = 10;
[PunRPC]
void OnCollisionEnter(Collision col)
{
if (col.transform.tag == "Bullet")
{
var pv = GetComponent<PhotonView>();
pv.RPC("AddjustCurrentHealth", RPCMode.All, curHealth);
}
}
[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();
}
[PunRPC]
void Die()
{
PhotonView.Destroy(gameObject);
}
}
Comment
Your answer
Follow this Question
Related Questions
Having a game object deal damage 0 Answers
I need help with my spell dealing damage over time. 1 Answer
Damage Indicator not showing correct position of attack. 0 Answers
Health Question 1 Answer
Damage script 0 Answers