mmorpg2d/Assets/Script/FarmItem.cs
2024-08-29 19:08:49 +05:30

59 lines
1.4 KiB
C#

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<FarmManager>().ShowPopUp(this);
}
}
private void OnTriggerExit2D(Collider2D other) {
if(other.tag == "Player"){
//
Debug.Log("GameObject : " + gameObject);
if(other.GetComponent<FarmManager>()==null){return;}
Debug.Log("active item : "+ other.GetComponent<FarmManager>().activeItem);
if(other.GetComponent<FarmManager>().activeItem.gameObject == gameObject){
other.GetComponent<FarmManager>().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);
}
}