Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Need help with cutting terrain trees down.

Discussion in 'Scripting' started by Ultimate_Cooper, Aug 4, 2020.

  1. Ultimate_Cooper

    Ultimate_Cooper

    Joined:
    Jul 27, 2020
    Posts:
    8
    WARNING! DON'T READ ON! EXTREME NOOB ALERT!!
    :D

    Hi!
    I'm trying to make a survival game, and my world is a terrain. I have used the terrain>trees option to build my environment. But, I need help cutting them down. I have NOOO clue. I checked some other posts on the forums, but they all seem so complex!! There has to be a simple way of doing it without having to create each tree individually!?
    -Thanks!
     
  2. bobisgod234

    bobisgod234

    Joined:
    Nov 15, 2016
    Posts:
    1,042
    There is no "simple" way to cut down trees, such a feature is too specific to a certain type of game to build-in.
     
  3. Ultimate_Cooper

    Ultimate_Cooper

    Joined:
    Jul 27, 2020
    Posts:
    8
    When I say simple, I just mean like not 40000 lines. Something more like 300 - 500.
     
  4. bobisgod234

    bobisgod234

    Joined:
    Nov 15, 2016
    Posts:
    1,042
    I suppose you could make the trees separate objects, add a trigger to them, and do something like this.

    Code (CSharp):
    1. void OnTriggerStay(collider c)
    2. {
    3.   if (c.gameObject.tag == "Player")
    4.   {
    5.     if (Input.GetMouseButtonDown(0)) // Might be problematic in OnTriggerStay, I can't remember
    6.     {
    7.       c.gameObject.GetComponent<Inventory>().AddWood(); //change this to however you handle player resources
    8.       Destroy(gameObject);
    9.     }
    10.   }
    11. }
     
  5. Ultimate_Cooper

    Ultimate_Cooper

    Joined:
    Jul 27, 2020
    Posts:
    8
    Thanks! I think what I'm going to do is add some trees that are 'Eligible to Harvest' Meaning you can only harvest some trees because the others might not have suitable wood. And, each one of those trees will be a separate object. Thanks! (PS I'm only just a beginner!) Shhhhhh!