FarmItem.cs 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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. {
  13. if (other.tag == "Player")
  14. {
  15. //ui
  16. other.GetComponent<FarmManager>().ShowPopUp(this);
  17. }
  18. }
  19. private void OnTriggerExit2D(Collider2D other)
  20. {
  21. if (other.tag == "Player")
  22. {
  23. //
  24. Debug.Log("GameObject : " + gameObject);
  25. if (other.GetComponent<FarmManager>() == null) { return; }
  26. Debug.Log("active item : " + other.GetComponent<FarmManager>().activeItem);
  27. if (other.GetComponent<FarmManager>().activeItem.gameObject == gameObject)
  28. {
  29. other.GetComponent<FarmManager>().HidePopUp();
  30. Debug.Log("**** player exit from farm item ! ****");
  31. }
  32. }
  33. }
  34. public void Farm()
  35. {
  36. CmdSetAvailability(false);
  37. }
  38. [Command]
  39. void CmdSetAvailability(bool val)
  40. {
  41. Debug.Log("This farming item is being used", gameObject);
  42. isAvailable = val;
  43. }
  44. public void DestroySelf()
  45. {
  46. if (isServer)
  47. {
  48. NetworkServer.Destroy(gameObject);
  49. }
  50. else
  51. {
  52. CmdDestroySelf();
  53. }
  54. }
  55. [Command]
  56. void CmdDestroySelf()
  57. {
  58. NetworkServer.Destroy(gameObject);
  59. }
  60. }