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 Mayday556 · Aug 07, 2013 at 03:08 AM · terrainfloatconvertinteger2d array

[Closed] Cannot convert types?

I have been working on random generation of objects and I came across an error, like I always do, and I can't figure this one out. I have been trying to set certain parts of the heightmap, and this was just a test to see if it would work, but the types aren't converting like they should! it says that in the for loop it can't convert the Heightmap[x, y] to Heightmap[buildingPlacementX, buildingPlacementY] when it should be able to...

 public void GenerateBuilding(Terrain buildingTerrain, GameObject building) {
         
         TD = buildingTerrain.terrainData;
         Heightmap = new float[TD.heightmapWidth, TD.heightmapHeight];
         
         float buildingPlacementX = Random.Range(10f, TD.size.x - 10f);
         float buildingPlacementZ = Random.Range(10f, TD.size.z - 10f);
         int buildingPlacementY = (int)buildingTerrain.SampleHeight(new Vector3(buildingPlacementX, 0, buildingPlacementZ));
         
         Instantiate(building, new Vector3(buildingPlacementX, buildingPlacementY, buildingPlacementZ), Quaternion.identity);
         
         for (float x = 0f; x < (float)TD.heightmapWidth; x++) {
             for (float y = 0f; y < (float)TD.heightmapHeight; y++) {
                 
                 if (Heightmap[x, y] == Heightmap[buildingPlacementX, buildingPlacementZ]) {
                     
                     Heightmap[x, y] = (float)buildingPlacementY;
                     
                 }
             }
         }
         
         TD.SetHeights(0, 0, Heightmap);
     }
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 cdrandin · Aug 07, 2013 at 03:11 AM 0
Share

Typically if you have an error it is helpful for others to know the error as well if you want any hope in someone helping unless they pretty much know what you are doing.

avatar image Mayday556 · Aug 07, 2013 at 03:13 AM 0
Share

Very sorry I was in a hurry, editing that now

avatar image Bunny83 · Aug 07, 2013 at 03:50 AM 0
Share

BTW: why is there a [closed] in front of your title when the question isn't closed?

2 Replies

· Add your reply
  • Sort: 
avatar image
-1

Answer by Mayday556 · Aug 07, 2013 at 03:52 AM

NVM, figured it out.

Comment
Add comment · Show 1 · 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 Bunny83 · Aug 07, 2013 at 03:53 AM 0
Share

That's not really an answer.

avatar image
0

Answer by Bunny83 · Aug 07, 2013 at 03:48 AM

buildingPlacementX and buildingPlacementZ are float values but you use them as index values for your array. You need an integer as index, or what do you think is element 2.315?

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

16 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

Related Questions

Convert a char to int / float 2 Answers

Positive to negative not working? 1 Answer

Timer - CS0029: Cannot implicitly convert type `float' to `bool' 1 Answer

Why aren't these numbers going down by 1. 1 Answer

Keep height at edge TerrainToolkit 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