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 /
  • Help Room /
avatar image
0
Question by upariver · Oct 31, 2016 at 06:29 PM · listsprecisiondouble

[C#] How to position a gameobject using double type numbers?

I need to get the previous gameobject in the list, however I have found that I cannot add anything that are not ints. What is the workaround this? How Can I increase an objects position in c# by 0.64 instead of 1?

Comment
Add comment · Show 4
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 doublemax · Oct 31, 2016 at 10:58 PM 1
Share

All methods regarding positioning or moving gameObjects take floats as parameters. Please show some code.

avatar image upariver doublemax · Nov 01, 2016 at 08:00 AM 0
Share

Its in this line. I cannot move it by 0.7 or any 0.something, only by 1 $$anonymous$$imum.

thisObject.transform.position = array_tiles[f].transform.position + new Vector3(0.7,0,0);

public void spawntiles() {

     for (int i = 0; i < int_tile_spawnrate; i++)
     {
         int f = i - 1;
         Vector3 previous_tile_location;
         GameObject thisObject;
        // Transform tform_thisObject = thisObject.transform.x;
         if (i == 0)
         {
            

             thisObject = Instantiate(Tiles) as GameObject;
             array_tiles.Add(thisObject);
             thisObject.transform.position = GameCamera.ScreenToWorldPoint(screenPosition);

         }
         if (i != 0)
         {
             thisObject = Instantiate(Tiles) as GameObject;
             array_tiles.Add(thisObject);
             thisObject.transform.position = array_tiles[f].transform.position + new Vector3(0.7,0,0);
             // previous_tile_location = array_tiles[f].transform.position + array_tiles[f].GetComponent<Collider>().bounds.size;
             // var vector_previous_tile_position =array_tiles[f].transform.position;
             // vector_previous_tile_position.x = vector_previous_tile_position + Tiles.;
         }





     }
 }
avatar image doublemax upariver · Nov 01, 2016 at 09:16 AM 1
Share
 thisObject.transform.position = array_tiles[f].transform.position + new Vector3(0.7,0,0);

This line doesn't even compile for me, because it complains that the Vector3 constructor takes only floats as parameters.

Try this ins$$anonymous$$d:

 new Vector3(0.7f, 0f, 0f);
Show more comments

1 Reply

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

Answer by LucianoMacaDonati · Oct 31, 2016 at 11:11 PM

I think you're misunderstanding array (or lists) indexes (Integers) and plain floating point numbers.

 transform.position += Vector3.Lerp(trasnform.position, myList[ index ], Time.deltatime * speed);
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 LucianoMacaDonati · Oct 31, 2016 at 11:12 PM 1
Share

Like @doublemax said, if you show some code we would be able to help you better ins$$anonymous$$d of guessing what the problem is.

avatar image upariver · Nov 01, 2016 at 08:01 AM 0
Share

Thank you for answering. I have posted code in @doublemax code.

avatar image LucianoMacaDonati · Nov 01, 2016 at 12:49 PM 1
Share

Hello @upariver,

I believe what you're looking for is to set a transform's position. You can't set the position member's individually (transform.position.x = 5). What you can do, is set the whole position Vector3:

 transform.position = new Vector3( 0.0f , 5.36f, 3.14f);

Since a Vector3 is conformed of 3 floats, you must add those 'f' to the end. I see you're trying to use this in array_tiles[f] where you should be using array_tiles[i] ins$$anonymous$$d (since i is the index of your forloop).

I recommend starting really slow on simple operations before jumping into for-loops and iterations. Try moving a single transform every frame, or scaling something up and then try doing it yo many objects. Good luck !

avatar image upariver LucianoMacaDonati · Nov 01, 2016 at 01:00 PM 0
Share

Thank you very much!

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

78 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

Related Questions

How to get type double to vector3? 0 Answers

What are the benefits of 1 unit per meter? 2 Answers

Problem operating with doubles 1 Answer

Why is my list bigger than it should be? 2 Answers

Recursive reference within a list 2 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