简体   繁体   中英

How can i make clone object invisible Unity

1.i have an issue when i start dragging object its clonning itself, i need that in panel zone(my object respawning in there) not in dropzone im trying to find solution for this can i make clone invisible? if i can how ?here is the code :

enter code here

public class DragHandler : MonoBehaviour, IBeginDragHandler, IDragHandler, IEndDragHandler { public enum Slot { 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");

    }






}

}

If you just want to make a GameObject invisible there are many ways to do it. You can, for example:

yourGameObject.SetActive(false);

You can also deactivate your gameobject Renderer

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

how to adapt it to your code is up to you.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM