1.i在我开始拖动对象自身的克隆时遇到问题,我需要在面板区域(我的对象在其中重新生成)不在dropzone中,我试图为此找到解决方案,我可以使克隆不可见吗?如果可以的话,代码在这里:
enter code here
公共类DragHandler:MonoBehaviour,IBeginDragHandler,IDragHandler,IEndDragHandler { 公共枚举广告位{ileri,sağa,sola,fonksiyon};
public Slot typeofMove;
public Transform ParentreturnTo = null;
public Transform PlaceholderParent = null;
GameObject placeholder = null;
public GameObject ileriprefab;
public GameObject x;
public GameObject panel;
public void OnBeginDrag(PointerEventData eventData)
{
placeholder = new GameObject();
placeholder.transform.SetParent(this.transform.parent);
LayoutElement le = placeholder.AddComponent<LayoutElement>();
le.preferredWidth = this.GetComponent<LayoutElement>().preferredWidth;
le.preferredHeight = this.GetComponent<LayoutElement>().preferredHeight;
le.flexibleWidth = 0;
le.flexibleHeight = 0;
placeholder.transform.SetSiblingIndex(this.transform.GetSiblingIndex());
//sibling index kartı aldıgımız yeri döndürür.
Debug.Log("OnBeginDrag");
ParentreturnTo = this.transform.parent;
PlaceholderParent = ParentreturnTo;
this.transform.SetParent(this.transform.parent.parent);
if (this.transform.parent.position == GameObject.FindGameObjectWithTag("carddroparea").transform.position)
{
x = Instantiate(moveforwardprefab, moveforvardprefab.transform.position, Quaternion.identity);
x.transform.SetParent(PlaceholderParent.transform);
//im trying to saying here if the object "this" in drop zone dont instantiate it or make it invisible ??????? but its not working
}
GetComponent<CanvasGroup>().blocksRaycasts = false;
}
public void OnDrag(PointerEventData eventData)
{
Debug.Log("OnDrag");
this.transform.position = eventData.position;
if (placeholder.transform.parent != PlaceholderParent)
placeholder.transform.SetParent(PlaceholderParent);
int newSiblingIndex = PlaceholderParent.childCount;
for (int i = 0; i < PlaceholderParent.childCount; i++)
{
//**parentreturnto. getchild(i)**//
if (this.transform.position.x < PlaceholderParent.GetChild(i).position.x)
{
newSiblingIndex = i;
// placeholder.transform.SetSiblingIndex(i);
if (PlaceholderParent.transform.GetSiblingIndex() < newSiblingIndex)
newSiblingIndex--;
break;
}
}
placeholder.transform.SetSiblingIndex(newSiblingIndex);
}
public void OnEndDrag(PointerEventData eventData)
{
Debug.Log("OnEndDrag");
this.transform.SetParent(ParentreturnTo);
this.transform.SetSiblingIndex(placeholder.transform.GetSiblingIndex());
//Kartın alındıgı yere konulması için gerekli
GetComponent<CanvasGroup>().blocksRaycasts = true;
Destroy(placeholder);
if (this.transform.parent.position == GameObject.FindGameObjectWithTag("panel").transform.position)
{
Destroy(x);
Debug.Log("destroyed");
}
if (x.transform.parent.position == GameObject.FindGameObjectWithTag("carddroparea").transform.position)
{
Destroy(x);
Debug.Log("destroyed");
}
}
}
答案 0 :(得分:0)
如果您只想使GameObject不可见,有很多方法可以做到。 您可以,例如:
yourGameObject.SetActive(false);
您还可以停用游戏对象渲染器
yourGameObject.GetComponent<Renderer>().enabled = false;
如何将其适应您的代码由您决定。