FarmItem.cs 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using Mirror;
  4. using UnityEngine;
  5. public class FarmItem : NetworkBehaviour
  6. {
  7. public string lootDrop;
  8. public float farmingTime = 30f;
  9. [SyncVar]
  10. public bool isAvailable = true;
  11. private void OnTriggerStay2D(Collider2D other) {
  12. if(other.tag == "Player"){
  13. //ui
  14. other.GetComponent<FarmManager>().ShowPopUp(this);
  15. }
  16. }
  17. private void OnTriggerExit2D(Collider2D other) {
  18. if(other.tag == "Player"){
  19. //
  20. Debug.Log("GameObject : " + gameObject);
  21. if(other.GetComponent<FarmManager>()==null){return;}
  22. Debug.Log("active item : "+ other.GetComponent<FarmManager>().activeItem);
  23. if(other.GetComponent<FarmManager>().activeItem.gameObject == gameObject){
  24. other.GetComponent<FarmManager>().HidePopUp();
  25. Debug.Log("**** player exit from farm item ! ****");
  26. }
  27. }
  28. }
  29. public void Farm(){
  30. CmdSetAvailability(false);
  31. }
  32. [Command]
  33. void CmdSetAvailability(bool val){
  34. Debug.Log("This farming item is being used", gameObject);
  35. isAvailable = val;
  36. }
  37. public void DestroySelf(){
  38. if(isServer){
  39. NetworkServer.Destroy(gameObject);
  40. }else{
  41. CmdDestroySelf();
  42. }
  43. }
  44. [Command]
  45. void CmdDestroySelf(){
  46. NetworkServer.Destroy(gameObject);
  47. }
  48. }