Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 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 Draghou · May 04, 2013 at 02:40 PM · objectpuzzleswapdraganddrop

How to swap textures?

Hi. I am making a puzzle game and I would like that id the player moves an object on the other thex would swap positions. Can I do it in one code or shall I wrote an other so when something is palced there it would get the place of the other object? If I can write it in one code, how can I make that if something is moved to an other object they swap positions? I guess with GetPosition. And how can I set that from where shall it get the new position? (So the player don't have to move exactly on the object just near to it)

Thanks for your help.

Comment
Add comment · Show 3
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 Draghou · May 08, 2013 at 06:25 PM 0
Share

Can semobody help? Something where I shouldshall start from?

avatar image Vonni · May 08, 2013 at 06:43 PM 0
Share

Take some time to write properly. Doesn't look like english is a problem for you, this is just you typing quickly and not giving a shit, annoying to read. Farewell to you sir.

avatar image Adamcbrz · May 08, 2013 at 06:50 PM 0
Share

@Draghou, your question is super difficult to follow. Please clarify.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by robertbu · May 08, 2013 at 07:24 PM

There are a number of related technical questions here. Without your code, it is difficult to give you advice. And as others have pointed out, your question is difficult to read.

  1. The first challenge is the dragging and dropping. Do you have that solved? If not search this list and you will find many answers. The ones involving OnMouseDown(), OnMouseDrag(), OnMouseUp() will be easiest to implement, but the Physics.Raycast() solutions will work as well.

  2. The second challenge is moving pieces to a specific location. Games like the one I think you are making look best if the pieces move to their new positions over time. Typically I like to make each piece know where it "home position" is and then if I need to move it just change the "home position" and let the piece do its own work. Look at Vector3.Lerp()as well as the numerous posts on this list about moving things over time.

  3. To detect when one piece is over the other, you will need to Raycast. Take a look at Physics.Raycast() plus any number of posts on raycasting on this list.

  4. If you've implement 1 - 3 above, you can swap pieces by simply swapping their home positions and allow the pieces to fly to their new positions.

Note your question asks about swapping textures. This will produce an instant change between the two pieces. That is one way to approach the problem, but unless you have a specific need in your game to swap textures, you could just swap the positions of the two pieces:

 Vector3 v3T = piece1.transform.position;
 piece1.transform.position = piece2.transform.position;
 piece2.transform.position = v3T;

Assuming the mesh for the two pieces is the same, this swap of position will look like a swap of textures.

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

14 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

Related Questions

Pulling Puzzler 2 Answers

Drag And drop objects mouse 2 Answers

Split Image 1 Answer

Swap objects with same tag? 1 Answer

Limiting Drag and Drop 1 Answer


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