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 am_012 · Aug 18, 2020 at 11:16 PM · inputobjectvector3cubecsv

Creating Objects using CSV file

I am trying to create an object( 2D Cube) and I am using a CSV file to get its x y and z coordinates I can read and log the coordinates, but they are string so I use a method to try and convert to float. But when I play the scene the objects are not created.

distance += distanceChange;

Vector3 clickPosition = new Vector3(float.Parse(data_values[0], CultureInfo.InvariantCulture.NumberFormat), float.Parse(data_values[1], CultureInfo.InvariantCulture.NumberFormat), float.Parse(data_values[2], CultureInfo.InvariantCulture.NumberFormat)); //Vector3 clickPosition = new Vector3(Convert.ToSingle(data_values[0]),

         GameObject cube = GameObject.CreatePrimitive(PrimitiveType.Cube);


         cube.transform.position = clickPosition;


        Debug.Log(data_values[0].ToString() + "   " + data_values[1].ToString() + " " + data_values[2].ToString());

I am using the float.Parse(data_values[0], CultureInfo.InvariantCulture.NumberFormat code to convert to float.

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 shishirchandrapoudel123 · May 03, 2021 at 03:07 AM 0
Share

Brother have your issue has been solved? I am working on the same project. Can you help me with this. I just need the code display the cube from the 8 coordinates store in CSV file. Would really appriciate if you can help me or ready to pay you if you are comfortable helping me

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by myzzie · Aug 18, 2020 at 11:47 PM

You'll have to either replace the periods with commas or change the cultureInfo

     if(float.TryParse(data_values[0], NumberStyles.Any, CultureInfo.InvariantCulture, out float x) && 
         float.TryParse(data_values[1], NumberStyles.Any, CultureInfo.InvariantCulture, out float y) && 
         float.TryParse(data_values[2], NumberStyles.Any, CultureInfo.InvariantCulture, out float z))
     {
         Vector3 clickPosition = new Vector3(x, y, z);
         GameObject cube = GameObject.CreatePrimitive(PrimitiveType.Cube);
         cube.transform.position = clickPosition;
         Debug.Log(data_values[0].ToString() + "   " + data_values[1].ToString() + " " + data_values[2].ToString());
     }
Comment
Add comment · Show 3 · 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 am_012 · Aug 19, 2020 at 01:25 AM 0
Share

It was not able to output the cubes even with this code, unfortunately. one thing i noticed is that when I debug the coordinates, for the first iteration it does X1, Y1, Z1 but then the next line it is X1, Y1, is there something wrong with my code

 void ReadCSVFile(){
        StreamReader strReader = new StreamReader("Assets/Resources/region - Sheet1.csv");
        bool  endOfFile = false;
        while(!endOfFile)
        {
            string data_string = strReader.ReadLine ();
            if (data_string == null){
                endOfFile = true;
                break;
            }
            var data_values = data_string.Split (',');
            for (int o =0; o < data_values.Length; o++)
            {
                Debug.Log("Value:" + o.ToString() + " " + data_values[o]);
 
            }
               distance += distanceChange;
               if(float.TryParse(data_values[0], NumberStyles.Any, CultureInfo.InvariantCulture, out float x) && 
                 float.TryParse(data_values[1], NumberStyles.Any, CultureInfo.InvariantCulture, out float y) && 
                 float.TryParse(data_values[2], NumberStyles.Any, CultureInfo.InvariantCulture, out float z))
      {
          Vector3 clickPosition = new Vector3(x, y, z);
          GameObject cube = GameObject.CreatePrimitive(PrimitiveType.Cube);
          cube.transform.position = clickPosition;
          Debug.Log(data_values[0].ToString() + "   " + data_values[1].ToString() + " " + data_values[2].ToString());
      }
        }
avatar image myzzie am_012 · Aug 19, 2020 at 10:11 AM 0
Share

Could you show me your writer as well? or a snippet of your csv file

avatar image am_012 myzzie · Aug 19, 2020 at 12:48 PM 0
Share

yes here

 -4,0.2,0
 -5,0.3,0
 -3.1,3.7,0
 4.2,3.8,0
 -2.3,0.4,0

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

194 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 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 to make flat object(Unity 2D) 1 Answer

Create a Custom Vector3 Object 2 Answers

Player moves too fast diagonally and accelerates too fast diagonally. 2 Answers

Smooth movement when input is pressed 1 Answer

Quaternion amount/value of rotation? 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