Advertisement
Guest User

superpuper

a guest
Jan 28th, 2012
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.26 KB | None | 0 0
  1. using UnityEngine;
  2.  
  3. using System.Collections;
  4.  
  5.  
  6.  
  7. public class MaterialHealth : MonoBehaviour {
  8.  
  9.     public int maxHealth=1;
  10.  
  11.     public int curHealth;
  12.  
  13.     public bool destroy=false;
  14.  
  15.     //public GameObject partsD;
  16.  
  17.     //public int count=4;
  18.  
  19.     //private int curCount=0;
  20.  
  21.     void Start () {
  22.  
  23.     curHealth = maxHealth;
  24.  
  25.     }
  26.  
  27.     void Update () {
  28.  
  29.         if(destroy==true)Destroy(gameObject);
  30.  
  31.         if(curHealth>maxHealth) curHealth = maxHealth;
  32.  
  33.         if(curHealth<0)curHealth=0;
  34.  
  35.         if(curHealth==0){
  36.  
  37.             //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));
  38.  
  39.             //if(curCount<count){Instantiate(partsD,rSpawn,Quaternion.identity);curCount+=1;}
  40.  
  41.             //if(curCount>=count)Destroy(gameObject);
  42.  
  43.             NetworkViewID nvi=transform.networkView.viewID;
  44.  
  45.             Destroy(gameObject);
  46.  
  47.             networkView.RPC("Destroy",RPCMode.OthersBuffered,nvi);
  48.  
  49.         }
  50.  
  51.     }
  52.  
  53. [RPC]
  54.  
  55.     void Destroy(NetworkViewID nvi){
  56.  
  57.             foreach(GameObject _item in GameObject.FindObjectsOfType(typeof(GameObject))){
  58.  
  59.             NetworkView _itemN=_item.GetComponent<NetworkView>();
  60.  
  61.             if(_itemN!=null){
  62.  
  63.             if(_item.networkView.viewID==nvi){         
  64.  
  65.                     MaterialHealth destroy=_item.GetComponent<MaterialHealth>();
  66.  
  67.                     if(destroy!=null){
  68.  
  69.                     destroy.destroy=true;
  70.  
  71.                 }}}}}
  72.  
  73. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement