using System.Collections; using System.Collections.Generic; using Mirror; using UnityEngine; public class FarmItem : NetworkBehaviour { public string lootDrop; public float farmingTime = 30f; [SyncVar] public bool isAvailable = true; private void OnTriggerStay2D(Collider2D other) { if(other.tag == "Player"){ //ui other.GetComponent().ShowPopUp(this); } } private void OnTriggerExit2D(Collider2D other) { if(other.tag == "Player"){ // Debug.Log("GameObject : " + gameObject); if(other.GetComponent()==null){return;} Debug.Log("active item : "+ other.GetComponent().activeItem); if(other.GetComponent().activeItem.gameObject == gameObject){ other.GetComponent().HidePopUp(); Debug.Log("**** player exit from farm item ! ****"); } } } public void Farm(){ CmdSetAvailability(false); } [Command] void CmdSetAvailability(bool val){ Debug.Log("This farming item is being used", gameObject); isAvailable = val; } public void DestroySelf(){ if(isServer){ NetworkServer.Destroy(gameObject); }else{ CmdDestroySelf(); } } [Command] void CmdDestroySelf(){ NetworkServer.Destroy(gameObject); } }