hey guys i tried everything i know but The RPC does not work When i open 2 clienents and when i shoot at a box withe the EnemyHealth script on it. that works when i shoot at it my rocket script does damage and
afther a few shots the cube die`s but the RPC is not Working Sending The damage Ifo to all the Players
also i am just beginning to understand C#
this is on my cube
using UnityEngine;
using System.Collections;
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);
}
void OnCollisionEnter(Collision collision)
{
if (collision.gameObject.tag == "Bullet")
{
AddjustCurrentHealth(-10);
//dh.ShowHealth(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)
Destroy(gameObject);
// healthBarLength = (Screen.width / 2) * (curHealth / (float)maxHealth);
}
}
this is on my rocket
using UnityEngine;
using System.Collections;
[PunRPC]
public class Rocket : MonoBehaviour
{
public float damage = 10.0f;
// Use this for initialization
void Start()
{
}
// Update is called once per frame
void Update()
{
if (Input.GetButtonDown("Fire1"))
{
RaycastHit hit;
Physics.Raycast(this.transform.position, transform.position, out hit);
// we hit something...
if (hit.collider != null)
{
hit.collider.GetComponent<PhotonView> ().RPC ("AddjustCurrentHealth", PhotonTargets.All, damage);
//hit.transform.GetComponent<Health>().Damage(10.0f);
}
}
}
}