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 Rebel8909 · Jul 22, 2014 at 03:32 AM · javascript

Empty Transform just attaches itself to an a prefab?

So I asked earlier to see if something was wrong with my code because initially the tiles wouldn't move at all. Well I solved that bit but now instead of all the tiles moving the Empty transform just seems to attach itself to a random Tile. When I click any of the adjacent tiles the tile I click gets shoved behind the tile the transform attached itself to.

I can't seem to pinpoint whats causing this any help would be awesome. Here's the code: #pragma strict

 var Temp : Transform;
 var Empty : Transform;
 var Tile : GameObject;
 
 function Start(){
 
 
 Tile.transform.position = transform.position;
 Empty.transform.position = transform.position;
 Temp.transform.position = transform.position;
 }
 
 function OnMouseUp(){                    
         if (Vector3.Distance(transform.position,Empty.position)==1){
         
         
         Temp.transform.position  = Empty.transform.position;
         Empty.transform.position = Tile.transform.position;
         Tile.transform.position = Temp.transform.position;
         
         }
 
     }    
Comment
Add comment · Show 5
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 calebheale · Jul 22, 2014 at 03:36 AM 0
Share

Would it be possible for you to post an image of what you are trying to accomplish as far as the movement goes? I'm having a tough time visualizing what you are trying to do here.

And if you can, possibly an image showing what is happening currently (the behavior you don't want). The transform isn't going to randomly attach itself to another object, so something about the behavior makes it look like that is happening when that probably isn't exactly the case.

avatar image Rebel8909 · Jul 22, 2014 at 04:08 AM 0
Share

Ok so when I put down the tile and set all the transforms and objects into the right slots on the Tile's scripts it looks like this before running it: alt text Then when I run it the transform puts itself on the bottom left block:

alt text

And finally when you actually click on a block it looks like it just moves behind the bottom left block:

alt text

avatar image calebheale · Jul 22, 2014 at 04:14 AM 0
Share

And what is the behavior you are looking for? Are you wanting those two bottom blocks to switch places? Also, what is your script attached to?

avatar image Rebel8909 · Jul 22, 2014 at 03:25 PM 0
Share

Well my scripts are attached to a Prefab, the tiles. The actions I want is that the cubes switch places with the "Empty" transform, leaving a new empty spot to be switched with. But what happens is the "Empty" transform hovers over a block, and if I delete said block it hovers over a new one. But when it hovers over a block that block never moves the entire game.

avatar image calebheale · Jul 23, 2014 at 01:12 AM 0
Share

Do you want this to happen on mouse up? It looks like both of those tiles are the same distance from the empty tile. If that is the case the swap will either get called on both tiles or neither which I don't think is what you want. If both tiles are the same distance and you only want to move one, how do you want the decision to be made on which tile gets moved?

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Can someone help me fix my Javascript for Flickering Light? 6 Answers

Script Doesn't work as intended 1 Answer

Setting Scroll View Width GUILayout 1 Answer

UnassignedReferenceException 1 Answer

Fall Damage OnCollisionEnter Script Help. 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