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 /
This question was closed Jul 22, 2014 at 03:35 PM by JusticeAShearing for the following reason:

The question is answered, the right answer was accepted.

avatar image
0
Question by JusticeAShearing · Jul 06, 2014 at 03:45 PM · gameobjectterrainarraytrees

Object-Spawning Script?

I am creating a game which requires trees that can be cut down.

The trees are the objects that I want spawned in the world, but it is far too much effort and cluttering-up of the hierarchy window to drag and drop each one over six full-size terrains, therefore I need a script to spawn these trees for me.

I also require the spawning script to spawn the trees with a custom script applied to them, one each, so that I may apply to the trees a chopping script that I have ready. I also require them to have colliders.

I will gratefully use C# and Boo scripts, but I would much prefer it if the scripts could be written in Java-Script, because I can fix errors and understand that language.

Thank you in advance for anybody with good intentions, from one who gives the solution, to one who wanted to help but didn't have the knowledge.

Comment
Comments Locked
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

1 Reply

  • Sort: 
avatar image
0
Best Answer

Answer by JusticeAShearing · Jul 22, 2014 at 03:34 PM

I ended up using this script. I spent a month trying to find this out, and eventually arrived back to where I started. With some amendments, this script is now error-free and my own. #pragma strict

 //This script finds all the terrain's trees then creates the tree object for user interaction for each tree position
 
 //The tree is a transform
 var treeFab : Transform;
 
 //The selected terrain is a certain terrain
 var grabTerrain : Terrain;
 //The trees are in an instance
 var trees : TreeInstance[];
  
 function Start ()
 {
     //For when i is worth zero, i gets the tree instances data on the active terrain and its length
     for (var i=0; i <Terrain.activeTerrain.terrainData.treeInstances.Length; i++)
     {
         //The terrain is that which is active
         var terrain : TerrainData  = Terrain.activeTerrain.terrainData;
         //The positions at which we are to make trees are that of the tree instances
         var pos = Vector3.Scale(Terrain.activeTerrain.terrainData.treeInstances[i].position,terrain.size)+ Terrain.activeTerrain.transform.position;
         
         //Create the trees
         Instantiate(treeFab, pos, Quaternion.identity);    
     }
 }

I hope that others find that they need not go on a learning-circle, and arrive right back to where they started after a month of learning their coding language.

This script is written in Java Script.

Comment
Comments Locked · Show 2 · 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 $$anonymous$$ · Apr 03, 2016 at 07:57 AM 0
Share

Does anyone have the time to convert this to C#? Thank you.

avatar image meat5000 ♦ $$anonymous$$ · Apr 03, 2016 at 08:21 AM 0
Share

You should take the time to learn how to do it yourself. There's really not a lot of difference.

You can do this by comparing the examples in the Scripting Reference.

Follow this Question

Answers Answers and Comments

22 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

Related Questions

tree terrain changes with game object!!! 1 Answer

Tree Instance Array Replacement 2 Answers

What is the best way to instatiate an array of connected GameObjects? 0 Answers

Apply trees On Terrain By Script 2 Answers

Transport unknown amout of objects with GameObject array 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