Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • 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 /
avatar image
0
Question by Dmsotir · Aug 26, 2014 at 09:01 PM · mousepuzzlelinking

OnMouseUp is nulling inputs

I am making a simple jigsaw puzzle and I am using OnMouseUp to lock my pieces after you release them. When I release the mouse over the piece it is coming back as null. That is to say, the variable that is being checked if its over a correct piece, is reading null within OnMouseUp but only within OnMouseUp. When the variable was outside it was correct, but the second it is inside OnMouseUp it becomes null.

 private Vector3 screenPoint;
     private Vector3 offset;
 
     public GameObject link;
     
     public bool selected = false;
 
     public int matchN = 1;
     public int matchS = 1;
     public int matchE = 1;
     public int matchW = 1;
     
     void Start () 
     {
     
     }
     
     void Update () 
     {
 
 
 
     }
 
     void OnTriggerStay2D (Collider2D myCollider)
     {
 
         if (myCollider.name == "north" && gameObject.collider2D.name == "south")        //checks if correct cube
         {
             if (gameObject.transform.parent.GetComponent<Tile>().selected == true)
             {
                 matchN = 2;
                 link = myCollider.transform.parent.gameObject;
                 Debug.Log (link + " Link");
             
             }
         }
         if (myCollider.name == "south" && gameObject.collider2D.name == "north")
         {
             if (gameObject.transform.parent.GetComponent<Tile>().selected == true)
             {
                 matchS = 2;
                 link = myCollider.transform.parent.gameObject;
             }
         }
 
         if (myCollider.name == "east" && gameObject.collider2D.name == "west")
         {
             if (gameObject.transform.parent.GetComponent<Tile>().selected == true)
             {
                 matchE = 2;
                 link = myCollider.transform.parent.gameObject;
             }
         }
 
         if (myCollider.name == "west" && gameObject.collider2D.name == "east")
         {
             if (gameObject.transform.parent.GetComponent<Tile>().selected == true)
             {
                 matchW = 2;
                 link = myCollider.transform.parent.gameObject;
             }
         }
 
     }
 
 
     
     void OnMouseDown()
     {
         if (gameObject.name == "piece")
         {
             //Debug.Log (matchN + "down");
             selected = true;
 
             screenPoint = Camera.main.WorldToScreenPoint(gameObject.transform.position);
         
             offset = gameObject.transform.position - Camera.main.ScreenToWorldPoint(new Vector3(Input.mousePosition.x, Input.mousePosition.y, screenPoint.z));
         }
 
 
 
     }
 
     void OnMouseUp()
     {
  
         matchN = 2;
         matchS = 2;
         matchE = 2;
         matchW = 2;
             
         Debug.Log (matchN + "up");
         Debug.Log (link + "up");
 
         selected = false;
 
         if(matchN == 2)
         {
             Debug.Log("Link north!");
             link.transform.parent.transform.position =  gameObject.transform.parent.position + new Vector3(0.0f,-1.0f,0.0f);
 
         }
         if(matchS == 2)
         {
             link.transform.parent.position =  gameObject.transform.parent.position + new Vector3(0.0f,1.0f,0.0f);
         }
         if(matchE == 2)
         {
             link.transform.parent.position =  gameObject.transform.parent.position + new Vector3(-1.0f,0.0f,0.0f);
         }
         if(matchW == 2)
         {
             link.transform.parent.position =  gameObject.transform.parent.position + new Vector3(1.0f,0.0f,0.0f);
         }
 
     }
 
     void OnMouseDrag()
     {
         if (gameObject.name == "piece")
         {
             Vector3 curScreenPoint = new Vector3(Input.mousePosition.x, Input.mousePosition.y, screenPoint.z);
         
             Vector3 curPosition = Camera.main.ScreenToWorldPoint(curScreenPoint) + offset;
             transform.position = curPosition;
         }
     }
 
 
 }








Comment
Add comment
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.

Follow this Question

Answers Answers and Comments

2 People are following this question.

avatar image avatar image

Related Questions

Making the Camera Follow the Mouse (Not LookAt) 2 Answers

Stacking Lego pieces 2 Answers

Need help finding why my onGUI() sliding image puzzle has errors! 1 Answer

How to scramble image pieces? 1 Answer

Concept of coding a win condition for a linking game (not asking for code) 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