Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 Un_Faced · Aug 23, 2018 at 10:51 PM · beginnerclones

I tried to transform the position of the clone of a prefab but it doesnt move.

In the first place thanks, and i have to say im new into unity.

whenever i click on a block(from a board, like a board game) i want the player to move to that block, but it doesnt move.

here´s the method that should move the player(a.k.a chip)

 public void Moving(float x, float z) 
         {
           
             chip.transform.position = new Vector3( x, 0f, z);
     
             Debug.Log(x + " " + z);
         }



eventhough i click on a block and it shows in the console the right position, the player doesnt move. one mmore thing, i dont know if its relevant but the player prefab has a "playerGraphic" sprite as child

Comment
Add comment · Show 1
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 Ermiq · Aug 24, 2018 at 01:32 PM 0
Share

Are you sure the transform doesn't move? Click on the player main game object in scene hierarchy so the transform will have axis arrows in editor window, then launch the game, click on the tile and check player's game object position.
Unity has some bugs with sprites, in my case it was sprite object which I was trying to use as a pivot for other objects and it turned out that sprite positions were inadequate when I tried to move it. $$anonymous$$aybe, your sprite doesn't move while the player root gameobject itself actually moves.

1 Reply

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

Answer by rainChu · Aug 24, 2018 at 06:06 AM

First of all, welcome to Unity!

Your code seems to be correct. I think that's why this question lasted so long without an answer to it. I'm not sure what is going wrong without seeing the rest of your program, the most I can do is provide general advice for tracking down the culprit. What is chip? You should run the game in the editor, using the play button, and look at the actual values of the Transform component. Did they change? If not, can you verify that chip is a reference to the Component or GameObject you think you're affecting? Another scenario that happens to me sometimes: I change the position of something, and something else I coded and then forgot about changes it back. If this is so, you can write a debug statement in the Update() event on the object you want to affect, and see what the position is each frame.

Good luck tracking it down!

Comment
Add comment · Show 4 · 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 Un_Faced · Aug 24, 2018 at 12:59 PM 0
Share

thanks for answering! (the chip is like the king on chess) the chipPrefab has the chipScript wich is this one. and it references the chipPrefab aswell(in the inspector) I´ve also tried to put "this.transform" or simple "transform" but ot has same result

 public class chipScript : $$anonymous$$onoBehaviour {
 
     public GameObject chip;
 
 
 
   
     void On$$anonymous$$ouseDown()
     {
 
     }
     public void $$anonymous$$oving(float x, float z) 
     {
 
         chip.transform.position = new Vector3( x, 0f, z);
 
         Debug.Log(x + " " + z);
     }
 
 
 
 }

here´s the "block script" too

  public GameObject tile;
   public chipScript chipScript;
 
 
     private float tileX;
     private float tileZ;
     
 
     void Start ()
     {
         tileX = tile.transform.position.x;
         tileZ = tile.transform.position.z;
     }
     void On$$anonymous$$ouseDown()
     {
         chipScript.$$anonymous$$oving(tileX, tileZ);
 
     }

and i´ve checked the coordinates in run time but they dont change neither.( And when I manually put something like 1,0,0 it moves) and again, thank you for answering!

avatar image rainChu Un_Faced · Aug 24, 2018 at 02:10 PM 0
Share

So what object are you assigning to chip? I want to be sure you understand how Unity works. this.transform and transform are equivalent when you're inside a $$anonymous$$onoBehaviour. It's the Transform on the same GameObject as your component. Your script looks fine at first glance, which probably means you're not setting up the Inspector correctly. First, you need to add your ChipScript to the gameObject. You should capitalize it, and just call it Chip. Some people do prefer adding Script on the end, but imo it's redundant. Then, you should attach it to your GameObject. Here is how I've done so, in my project: https://rainChu.com/s/tG.png Once your $$anonymous$$onoBehaviour is attached as a Component on your GameObject, modifying the transform property on it will work:

 public void $$anonymous$$oving(float x, float z) 
 {
     transform.position = new Vector3( x, 0f, z);
     Debug.Log(x + " " + z);
 }


In general, you only need to assign a GameObject in the inspector when you need to reference a different object. You can always find the GameObject that your chipScript is attached to with the gameObject property. Try this, and let me know if it helps!

avatar image Un_Faced rainChu · Aug 25, 2018 at 03:58 PM 0
Share

I´ve checked everything and, as I instantiate a clone of the prefab, it seems I have to reference the clone ins$$anonymous$$d of the prefab(i dont really know why). I mean, when in run time i change the reference of the chip to the chip(clone), it actually works.

Anyways by reading your answers I´ve solved my issue, thanks!

Show more comments

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

98 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

Related Questions

How do you save the position of clone prefabs in a text file? 1 Answer

how do I save a script when access is denied? 0 Answers

LoadLevel when colliding an object and clicking on it ? 1 Answer

Months after I left my Bootcamp demo alone, I can't see anything anymore.. 1 Answer

Trying to get my pong AI to work 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