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 AR_Rizvi · Oct 03, 2014 at 06:29 AM · terraintrees

Apply trees On Terrain By Script

i am trying to make a script which can save the position of the trees which has been painted on terrain and can apply it in some other project

it is still in building phase and i am unable to apply trees on a terrain here i need help i can not find any solution of how i can apply trees on terrain while i have only its position Help here would be appreciated Thanks AR

Here is my code f

 void Save_tress()
     {
         Prototype_1_position.Clear();
         Prototype_2_position.Clear();
         Prototype_3_position.Clear();
         Prototype_4_position.Clear();
 
     Terrain[]    terrian_save = (Terrain[]) GameObject.FindObjectsOfType(typeof(Terrain));
 
         foreach(Terrain Terra in terrian_save)
         {
             My_trees = Terra.terrainData.treeInstances;
             
             
             foreach (TreeInstance tre in My_trees)
             {
                 
   
                 
                 if(tre.prototypeIndex == 0 )
                 {
                     float x = Terra.terrainData.size.x * tre.position.x ;
                     float y = Terra.terrainData.size.y * tre.position.y ;
                     float z = Terra.terrainData.size.z * tre.position.z ;
                     
                     x = x + Terra.transform.position.x ;
                     y = y + Terra.transform.position.y ;
                     z = z + Terra.transform.position.z ;
                     
                     Vector3 abc = new Vector3(x,y,z);
                         Prototype_1_position.Add(abc);
                     
                 }
                 if(tre.prototypeIndex == 1 )
                 {
                     float x = Terra.terrainData.size.x * tre.position.x ;
                     float y = Terra.terrainData.size.y * tre.position.y ;
                     float z = Terra.terrainData.size.z * tre.position.z ;
                     
                     x = x + Terra.transform.position.x ;
                     y = y + Terra.transform.position.y ;
                     z = z + Terra.transform.position.z ;
                     
                     Vector3 abc = new Vector3(x,y,z);
                         Prototype_2_position.Add(abc);
                     
                 }
                 if(tre.prototypeIndex == 2 )
                 {
                     float x = Terra.terrainData.size.x * tre.position.x ;
                     float y = Terra.terrainData.size.y * tre.position.y ;
                     float z = Terra.terrainData.size.z * tre.position.z ;
                     
                     x = x + Terra.transform.position.x ;
                     y = y + Terra.transform.position.y ;
                     z = z + Terra.transform.position.z ;
                     
                     Vector3 abc = new Vector3(x,y,z);
 //                        Prototype_3_position.Add(abc);
                     
                 }
                 if(tre.prototypeIndex == 3 )
                 {
 //                        Prototype_4_position.Add(abc);
                         
                 }
                 if(tre.prototypeIndex == 4 )
                 {
 //                Prototype_5_position.Add(abc);
                         
                 }
                 if(tre.prototypeIndex == 5 )
                 {
 //                    Prototype_6_position.Add(abc);
                     
                 }
                 
                 Debug.Log(Prototype_1_position.Count);
                 Debug.Log(Prototype_2_position.Count);
                 Debug.Log(Prototype_3_position.Count);
             }
         }
         }
 
     void Apply_Trees()
     {
         Terrain[]    terrian_save = (Terrain[]) GameObject.FindObjectsOfType(typeof(Terrain));
 
         foreach(Terrain Terra in terrian_save)
         { 
             foreach(Vector3 newPOs_1  in Prototype_1_position)
             {
                 Instantiate(Tree_prefab_1 ,newPOs_1 ,Quaternion.identity);
 
             }
             foreach(Vector3 newPOs_2 in Prototype_2_position)
             {
                 Instantiate(Tree_prefab_2 , newPOs_2 ,Quaternion.identity);
                 
             }
             foreach(Vector3 newPOs_3  in Prototype_3_position)
             {
                 Instantiate(Tree_prefab_3 , newPOs_3 ,Quaternion.identity);
                 
             }
         }
 
     }
 
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 AR_Rizvi · Oct 03, 2014 at 10:20 AM 0
Share

Anyone ???

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by unimechanic · Oct 07, 2014 at 03:27 PM

http://forum.unity3d.com/threads/how-to-place-trees-during-runtime.260253/

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 William4458 · Jan 16, 2017 at 03:21 PM

Use raycasts to spawn your trees at the perfect height.

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

28 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

Related Questions

How to add Color to my terrain 3 Answers

How Do I Produce Lots Of Copies Of A Tree With The Scripts etc. 0 Answers

The name 'Joystick' does not denote a valid type ('not found') 2 Answers

Terrain Object Distance 1 Answer

How do I test if car is grounded to stop it from driving in mid-air? 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