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 OfirC · Jan 13, 2015 at 07:03 PM · pass

Dont let an object pass the screen sides

So , i have an object which can be moved by mouse dragging. the object can only move left or right but when it moves too left or too right it passes the wall and the object is invisble..

P.S :With C# and I need it to work on all the resolutions

     Vector3point=Camera.main.ScreenToWorldPoint(Input.mousePosition);
  point.z = gameObject.transform.position.z;
  point.y=gameObject.transform.position.y; 
 gameObject.transform.position = point;
 



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

2 Replies

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by homer_3 · Jan 13, 2015 at 10:58 PM

I think this post will do what you need http://answers.unity3d.com/questions/798586/limit-movement-of-object-based-on-screen-size-unit.html

Comment
Add comment · Show 7 · Share
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
avatar image OfirC · Jan 14, 2015 at 10:42 AM 0
Share

Still cant get this to work.. How could i make this to not pass the screen sides?(I need only limit on the X asix) Vector3point=Camera.main.ScreenToWorldPoint(Input.mousePosition); point.z = gameObject.transform.position.z; point.y=gameObject.transform.position.y; gameObject.transform.position = point;

avatar image homer_3 · Jan 14, 2015 at 01:16 PM 0
Share

What code did you try? You just pasted the same code in your OP again. Did you look at the code in the link?

avatar image OfirC · Jan 14, 2015 at 01:28 PM 0
Share

I tried this: Vector3 pos = Camera.main.WorldToViewportPoint(Input.mousePosition); pos.x = $$anonymous$$athf.Clamp(pos.x, 0.07f, 0.93f); pos.y = $$anonymous$$athf.Clamp(pos.y, 0.07f, 0.03f); gameObject.transform.position = Camera.main.ViewportToWorldPoint(pos);

But when im trying to drag the object he keep sticking to the right-down corner of the screen

avatar image homer_3 · Jan 14, 2015 at 01:32 PM 0
Share

In your 1st line you should be using gameObject.transform.position not the mouse position. You can set the gameObject's position to anything you want before the bounding code. Then that bounding code will push it into view of the camera. Also, if you don't care about bounding the Y coordinate, you can leave that line out.

avatar image OfirC · Jan 14, 2015 at 01:34 PM 0
Share

About the 1st line , i would like to move the object by mouse dragging it..so i must to use the mouse pos, right?

Show more comments
avatar image
0

Answer by SheZii · Feb 07, 2019 at 08:23 AM

If you want to clamp/restrict gameobjects on the boundary of Minimap, here are the links


Youtube: https://www.youtube.com/watch?v=xW4zZQhRKlI
Step by step tutorial: http://techscenarios.com/unity3d-clamp-objects-on-edges-of-minimap-clamp-on-minimap-boundary-free-scripts-part-4/

Comment
Add comment · Share
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

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Alpha blending with more than one pass 0 Answers

How to pass data through scenes? 0 Answers

How to draw a mesh multiple times with different shader parameters 1 Answer

when mouse pass over a button,the console print some content 1 Answer

Get color of pixel before pass: prefer cg, shaderlab is last resort 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