• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
  • Help Room /
avatar image
Question by sahandsh2 · Dec 02, 2020 at 12:34 AM · disappeardrop

dropping dissapearing problem

hi when i drop my object disspears or go t out side of screen or another place please help me this my code: and yes i dont own ts code i just editit using System.Collections; using System.Collections.Generic; using UnityEngine;

 public class draganddrop : MonoBehaviour
 {
     private GameObject startparent;
     public GameObject canvas;
     private bool isdraging = false;
     private Vector2 startposition;
     private bool isoverdropzone1 = false;
     public GameObject dropzone1;
     private bool isoverdropzone2 = false;
     public GameObject dropzone2;
     public GameObject gauge1;
     public GameObject gauge2;
     public GameObject right1;
     public GameObject right2;
     public GameObject left1;
     public GameObject left2;
     public GameObject center1;
     public GameObject center2;
     private bool isovergauge1 = false;
     private bool isovergauge2 = false;
     private bool isoverright1 = false;
     private bool isoverright2 = false;
     private bool isoverleft1 = false;
     private bool isoverleft2 = false;
     private bool isovercenter1 = false;
     private bool isovercenter2 = false;
     private void awake()
     {
         canvas = GameObject.Find("canvas");
 
     }
     // Start is called before the first frame update
     void Start()
     {
         
     }
 
     // Update is called once per frame
     void Update()
     {
         if(isdraging)
         {
             transform.position = new Vector2(Input.mousePosition.x, Input.mousePosition.y);
             transform.SetParent(canvas.transform, true);
         }
     }
     public void begindrag()
     {
         startparent = transform.parent.gameObject;
         startposition=transform.position;
         isdraging = true;
     }
     public void OnCollisionEnter2D(Collision2D collision)
     {
         isoverdropzone1 = true;
         isoverdropzone2 = true;
         isovergauge1 = true;
         isovergauge2 = true;
         isoverright1 = true;
         isoverright2 = true;
         isoverleft1 = true;
         isoverleft2 = true;
         isovercenter1 = true;
         isovercenter2 = true;
         dropzone1 = collision.gameObject;
         dropzone2 = collision.gameObject;
         gauge1 = collision.gameObject;
         gauge2 = collision.gameObject;
         right1 = collision.gameObject;
         right2 = collision.gameObject;
         left1 = collision.gameObject;
         left2 = collision.gameObject;
         center1 = collision.gameObject;
         center2 = collision.gameObject;
     }
     private void onCollisionExit2D(Collision collision)
     {
         isoverdropzone1 = false;
         isoverdropzone2 = false;
         isovergauge1= false;
         isovergauge2 = false;
         isoverright1 = false;
         isoverright2 = false;
         isoverleft1 = false;
         isoverleft2 = false;
         isovercenter1 = false;
         isovercenter2 = false;
         dropzone1 = null;
         dropzone2 = null;
         gauge1 = null;
         gauge2 = null;
         right1 = null;
         right2 = null;
         left1 = null;
         center1 = null;
         center2 = null;
     }
     public void enddrag()
     {
         isdraging = false;
         if (isoverdropzone1)
         {
             transform.SetParent(dropzone1.transform, false);
 
         }
         else if (isoverdropzone2)
         {
             transform.SetParent(dropzone2.transform, false);
         }
         else if (isovergauge1)
         {
             transform.SetParent(gauge1.transform, false);
         }
         else if (isovergauge2)
         {
             transform.SetParent(gauge2.transform, false);
         }
         else if (isoverright1)
         {
             transform.SetParent(right1.transform, false);
         }
         else if (isoverright2)
         {
             transform.SetParent(right2.transform, false);
         }
         else if (isoverleft1)
         {
             transform.SetParent(left1.transform, false);
         }
         else if (isoverleft2)
         {
             transform.SetParent(left2.transform, false);
         }
         else if (isovercenter1)
         {
             transform.SetParent(center1.transform, false);
         }
         else if (isovercenter2)
         {
             transform.SetParent(center2.transform, false);
         }
         else
         {
             transform.position = startposition;
             transform.SetParent(startparent.transform, false);
         }
     }
 
 }
 
Comment

People who like this

0 Show 0
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

209 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

c# Need help with a simple inventory, 3 slot hotbar. 1 Answer

Object disappears from camera but are still in scene. 0 Answers

Mobile Version: How to pickup and drop an item. 1 Answer

Objects disappears when more than 2 Objects share the same material [android] 0 Answers

reduce FPS drops from Shuriken Particle System in 2D 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges