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 Alex_S · Jun 23, 2011 at 11:04 PM · terrainrealtimeediting

Real-time terrain editor?

Ok so I have this code:

 using UnityEngine;
 using System.Collections;
 
 public class TerrainEditing : MonoBehaviour {
     private Ray ray;
     private RaycastHit hit;
     public Terrain terrain;
     
     void Update () {
         if (Input.GetMouseButtonDown(0))
         {
             ray = Camera.main.ScreenPointToRay(Input.mousePosition);
             if (Physics.Raycast(ray, out hit, 100))
             {
             Vector3 pos = hit.point;
             terrain.terrainData.SetHeights((int)pos.x, (int)pos.y, new float[100,100]);
             }
         }
     }
 }

But for some reason, this doesn't work! I just want to click anywhere on the terrain and have it raise to what height I want.

Can anyone see something wrong with this code?

Thanks,

Alex

Comment
Add comment
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

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by Dreamblur · Jun 23, 2011 at 11:45 PM

You're trying to access terrain which hasn't been initialized. What you should be doing instead is creating a new TerrainData, using the methods in that TerrainData to initialize the terrain settings, and then calling Terrain.CreateTerrainGameObject(the newly created TerrainData).

It's easier to just instantiate a terrain prefab though. 0_0

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
avatar image
0

Answer by Alex_S · Jun 24, 2011 at 12:10 AM

What if I already have a terrain in game, though? I linked my public terrain variable to the active terrain in my scene.

Excuse my stupidity, I'm still trying to get used to Unity's 'coding'. :p

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 Dreamblur · Jun 24, 2011 at 12:43 AM 0
Share

Terrain.Flush

function Flush () : void

Description

Flushes any change done in the terrain so it takes effect.

avatar image HolBol · Jun 24, 2011 at 01:00 AM 0
Share

Dude, $$anonymous$$_S, don't post comments as Answers.

avatar image Alex_S · Jun 24, 2011 at 01:06 AM 0
Share

Sorry, this is my first time using answers... lol... I forgot to read. :p And thanks Dreamblur. I'll try it and see what happens.

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Sharper terrain painting 0 Answers

Why can I not affect terrain height? 0 Answers

Preventing characters falling through world when altering terrain at runtime 1 Answer

Terrain collision detection with another collider - single vertex of heightmap doesn't collide! 0 Answers

Mesh Doesn't Reset Upon Leaving Game Mode 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