Search Unity

Really need Help (terrain access)

Discussion in 'Scripting' started by micuccio, Nov 23, 2014.

  1. micuccio

    micuccio

    Joined:
    Jan 26, 2014
    Posts:
    143
    Hi Guys,

    I am really sorry to bother you, but I am kind of desperate!

    Here is my request :
    I need to replace a tree painted on the terrain with the prefab one.
    I need of course to know the position,scale and rotation in order to repace it correctly.

    Any suggestions?
    Thanks,
     
  2. federicopintaluba

    federicopintaluba

    Joined:
    Oct 19, 2014
    Posts:
    13
    What is "a tree painted", some kind of texture? Is at least a GameObject?

    If it is a GameObject, create a script on in and in the Awake() function just instantiate the prefab at the same position, rotation and scale of the texture, if this solution may work for you, let me know and I will explain it to you with more detail.
     
  3. micuccio

    micuccio

    Joined:
    Jan 26, 2014
    Posts:
    143
    Hey Thanks for reply!
    Yes it may fits!
    I suppose the best way is to use raycast to identify the object position and rotation.
    I recently abandoned the idea to use the Unity terrain tools to "paint" the trees. Apparently there are no really benefits.
    Do you suggests any tutorial/guide how to use the raycast?

    I am pretty noob in that.
     
  4. federicopintaluba

    federicopintaluba

    Joined:
    Oct 19, 2014
    Posts:
    13
    If the texture you are painting is a gameobject, create a new script and attach it to the texture.

    Create a public GameObject variable to set the prefab you want to invoke.

    The Awake() function must look like the follow code:

    Code (CSharp):
    1. void Awake(){
    2.        Instantiate(prefabVar, transform.position, transform.rotation);
    3. }
    Where "prefabVar" is the public GameObject you set.

    Go to the inspector and set the prefab in that variable, save the whole texture as a prefab, then just paint that prefab, it will instantiate the preset prefab in prefabVar.

    Hope you unsterstood!