C# 如何使克隆对象不可见

C# 如何使克隆对象不可见,c#,object,unity3d,clone,invisible,C#,Object,Unity3d,Clone,Invisible,1.我有一个问题,当我开始拖动对象时,它会自动克隆,我需要在面板区域(我的对象会在那里重生)而不是在dropzone,我正在尝试找到解决方案,我可以让克隆不可见吗?如果我可以怎么做?以下是代码: enter code here 公共类DragHandler:MonoBehavior、IBeginDragHandler、IDragHandler、IENDragHandler { 公共enum插槽{ileri、sağa、sola、fonksiyon} public Slot typeofMove;

1.我有一个问题,当我开始拖动对象时,它会自动克隆,我需要在面板区域(我的对象会在那里重生)而不是在dropzone,我正在尝试找到解决方案,我可以让克隆不可见吗?如果我可以怎么做?以下是代码:

enter code here
公共类DragHandler:MonoBehavior、IBeginDragHandler、IDragHandler、IENDragHandler { 公共enum插槽{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");

    }






}
移动的公共插槽类型;
public Transform ParentreturnTo=null;
公共转换占位符父项=null;
游戏对象占位符=null;
公共游戏对象;
公共游戏对象x;
公共游戏对象面板;
公共void OnBeginDrag(PointerEventData事件数据)
{
占位符=新游戏对象();
占位符.transform.SetParent(this.transform.parent);
LayoutElement le=placeholder.AddComponent();
le.preferredWidth=此.GetComponent().preferredWidth;
le.preferredHeight=此.GetComponent().preferredHeight;
le.flexibleWidth=0;
le.flexibleHeight=0;
占位符.transform.SetSiblingIndex(this.transform.GetSiblingIndex());
//兄弟姐妹指数kartıaldıgımız yeri döndürür。
Log(“OnBeginDrag”);
ParentreturnTo=this.transform.parent;
占位符parent=ParentreturnTo;
this.transform.SetParent(this.transform.parent.parent);
if(this.transform.parent.position==GameObject.FindGameObjectWithTag(“carddroparea”).transform.position)
{
x=实例化(moveforwardprefab、moveforvardprefab.transform.position、Quaternion.identity);
x、 SetParent(占位符parent.transform);
//我想说的是,如果drop zone中的对象“this”没有实例化它或使它不可见,但它不工作
}
GetComponent().blocksRaycasts=false;
}
public void OnDrag(PointerEventData事件数据)
{
Debug.Log(“OnDrag”);
this.transform.position=eventData.position;
if(placeholder.transform.parent!=placeholder parent)
placeholder.transform.SetParent(placeholder父级);
int newSiblingIndex=placeholder parent.childCount;
对于(int i=0;i

}

如果你只是想让游戏对象不可见,有很多方法可以做到。 例如,您可以:

yourGameObject.SetActive(false);
您还可以停用游戏对象渲染器

yourGameObject.GetComponent<Renderer>().enabled = false;
yourGameObject.GetComponent().enabled=false;

如何使其适应您的代码取决于您。

欢迎使用堆栈溢出。为了让更多的人对你的问题感兴趣,并有更高的机会得到一个好的答案,请点击查看。现在,帮你是不可能的。编辑你的问题,试着更清楚你的疑问是什么。另外,不要发布你的全部代码;相反,提供一个答案。如果有效,请记住接受答案,这样每个人都知道什么是正确答案。如果你有不同的想法,就尽量说得更具体一些。