Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using System.Collections;
- public class MaterialHealth : MonoBehaviour {
- public int maxHealth=1;
- public int curHealth;
- public bool destroy=false;
- //public GameObject partsD;
- //public int count=4;
- //private int curCount=0;
- void Start () {
- curHealth = maxHealth;
- }
- void Update () {
- if(destroy==true)Destroy(gameObject);
- if(curHealth>maxHealth) curHealth = maxHealth;
- if(curHealth<0)curHealth=0;
- if(curHealth==0){
- //Vector3 rSpawn=new Vector3(transform.position.x+Random.Range(-0.5f,0.5f),transform.position.y+Random.Range(-0.5f,0.5f),transform.position.z+Random.Range(-0.5f,0.5f));
- //if(curCount<count){Instantiate(partsD,rSpawn,Quaternion.identity);curCount+=1;}
- //if(curCount>=count)Destroy(gameObject);
- NetworkViewID nvi=transform.networkView.viewID;
- Destroy(gameObject);
- networkView.RPC("Destroy",RPCMode.OthersBuffered,nvi);
- }
- }
- [RPC]
- void Destroy(NetworkViewID nvi){
- foreach(GameObject _item in GameObject.FindObjectsOfType(typeof(GameObject))){
- NetworkView _itemN=_item.GetComponent<NetworkView>();
- if(_itemN!=null){
- if(_item.networkView.viewID==nvi){
- MaterialHealth destroy=_item.GetComponent<MaterialHealth>();
- if(destroy!=null){
- destroy.destroy=true;
- }}}}}
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement