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
1
Question by Elit3d · Jan 30, 2014 at 05:23 PM · playerobjecttree

How would I properly put my script on multiple trees?

So I have programmed a script so that when the player is within a certain distance of the tree, they can gather wood from it. My only issue is that I want to include this for every tree. Is there an easy way to do this than placing every tree individually on the map?

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
2
Best Answer

Answer by getyour411 · Jan 30, 2014 at 11:08 PM

I'm going to suggest that the answer is No (short of procedural generation), which no offense to the OP, does not sound like an option he is ready to tackle just yet. OP originally said he doesn't want to place them one by one which is what, in the end, still happens with prefabs. I suspect he's asking if he can add a script to a tree, use that tree prefab in the Terrain Tree PAINTER and paint the trees - there answer is no, that will not work. Scripts attached to trees that are painted via Terrain tree painter do not work.

Comment
Add comment · Show 17 · 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 Elit3d · Jan 30, 2014 at 11:14 PM 0
Share

Thanks for the answer. Now we're getting somewhere. What do you suggest is the best way to get the trees on the terrain without placing them one by one?

avatar image getyour411 · Jan 30, 2014 at 11:25 PM 0
Share

Since the painter is not an option, really the only way is via script/procedure generated placement but that has issues too.

You probaby don't want trees scattered willynilly on your terrain, so how do you control where? There'll have to be zones or coords or some control structure.

One other lesson learned when I went down this road, is that mixing hand-placed vs painted trees can yield some funky visual results. Hard to explain but if you paint some trees then place some trees (either via hand or script) and Play & approach the tree area where they are mixed, you'll see how some trees seem to jump in front of others. At least that's what I saw when I last did this.

Unfortunatey I don't have a better answer because I put this issue on hold for my gamedev to work on a few other parts and haven't gotten back to it.

avatar image Elit3d · Jan 30, 2014 at 11:41 PM 0
Share

Its gonna be on a 4000x4000 terrain square and its also a survival game so I want the player to be able to chop down any tree they come across

avatar image AlucardJay · Jan 31, 2014 at 03:28 AM 2
Share

This will be very tricky to interact with trees that are painted on the terrain, but it is possible.

On finding a tree and hitting its collider, the collider returned would be the terrain collider.

You would have to read the terrain data to find the tree you are colliding with, and then remove it from the terrainData.treeInstances list.

You can see an example of reading and modifying treeInstances data in my answer here : Remove Underwater Trees

Another way could be to paint trees without colliders, then use ideas from this answer to generate a collider at the tree being chopped position and work with that.

avatar image AlucardJay · Jan 31, 2014 at 05:43 PM 1
Share

Recently stumbled upon this, think it's what you're after :

  • http://www.youtube.com/playlist?list=PLB4DA4F8BDC3B82EE

  • Part 22: Timed Trees : http://www.youtube.com/watch?v=h9I7cyYnrP$$anonymous$$

  • Part 25: Chopping Trees : http://www.youtube.com/watch?v=$$anonymous$$otIJ$$anonymous$$YQ7Dw

Show more comments
avatar image
0

Answer by HobbyKid · Jan 31, 2014 at 05:02 AM

I have your answer. Got a bit excited cause as noob as I am, this question I can actually answer.

To do this go into your project folder and take the tree you want the player gather from and drag it into your scene. Then attach the script to the tree in your scene. This is so you have the collider style script your referring to on that inparticular game object. Next save that tree as a seperate gameobject; save it to your asset folder.

Finally to place this tree with the collider go to heirarchy--> terrain--> add trees. Be sure to add the tree that you just put the script on . Then you can mass place trees easily.

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 getyour411 · Jan 31, 2014 at 05:07 AM 0
Share

I wish that worked, but unfortunately its the scenario we discussed above, trees from the Terrain tree paint do not work with the scripts you assigned to the tree prefab before painting.

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

24 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

Related Questions

how to change object 0 Answers

Hey, i can't figure out, what my problem is. I want to Add something into the player's Inventory, but before that it should check, whether there is an Item with the same name in it, or not and if yes, if the maxAmount for that slot is reached. 0 Answers

Object won't collide with Player unless Player is moving 1 Answer

Distance from tagged objects problem 1 Answer

Changing player object UNET 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