• 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
Question by Extaze · Nov 24, 2013 at 04:42 PM · terraingenerationheightmapterraindata

How to generate a complete terrain via Script

Hi.

I'm trying to create a basic game in w$$anonymous$$ch you have different maps. I would like to allow the player to have its own maps. Here is ho i plan to do t$$anonymous$$s : A map file is a basic arc$$anonymous$$ve containing :

  • The height map

  • The texture map

The height map can be easily generated by TerrainData.SetHeights() from a matrice containing heights. But. How to set the texture of a Terrain from a point ? I'd like to do somet$$anonymous$$ng like :

 // Open file, read file, split to get rows, re-split to get a 2D array of heights.
 float[][] heights = fileToHeihgts(filepath);
 
 // Open file, read file, split to get rows, re-split to get a 2D array of string,
 // and use Resources.LoadAssetAtPath to load texture from string.
 Texture[][] textures = fileToTexture(filepath);
 
 TerrainData tData = new TerrainData();
 tData.SetHeight(0, 0, heights);
 tData.SetTextures(0, 0, textures); 

But i don't see any way to do "SetTextures". I saw a guy who created one terrain by texture, and set alphamaps to each of them (each point (x,y) has only one terrain visible). Is there another way ?

Thanks.

Comment

People who like this

0 Show 2
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 nastasache · Nov 25, 2013 at 10:36 AM 0
Share

You have to use TerrainData.detailPrototypes and DetailPrototype.prototypeTexture to play with terrain textures at runtime.

avatar image Extaze · Nov 25, 2013 at 11:53 AM 0
Share

But you can set only one texture :/

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

18 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

Related Questions

Raise a *circle* on a terrain 1 Answer

How do you choose the heights of a terrain using code? 1 Answer

Generated terrain heightmap is flipped from the alphamap. 1 Answer

Error while trying to access a Terrain's terrainData. 1 Answer

I've written a script to create dynamic height maps. How do I use those height maps to generate dynamic procedural terrains? 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