- Home /
Initial rotation of trees with a script
Hi I tried with this simple C# script to automatically rotate trees placed by the terrain tree paint tool. I created two 3 prefabs and then added them to tree palette. But seems that when the tree is used alongside with terrain the script is not runned. This script only works when placing trees manually. That's a bit disappointing.
using UnityEngine;
using System.Collections;
public class RotatingTree : MonoBehaviour {
Vector3 Rotation;
// Use this for initialization
void Awake() {
gameObject.transform.Rotate(0,Random.Range(0,360),0);
}
void Start () {
Rotation = new Vector3(0,Random.Range(0,360),0);
}
// Update is called once per frame
void Update () {
//gameObject.transform.Rotate(Rotation); //test
gameObject.transform.Rotate(0,Random.Range(0,360),0);
}
}
seems that nether "Awake" function is called in this case. Having many trees all rotated the same manner is not very good looking.
Answer by ricardo_arango · Sep 20, 2012 at 02:43 AM
You can't rotate the Trees in a Terrain. If you look at the documentation for the TreeInstance struct, you can see the parameters that you can tweak for a tree instance:
http://docs.unity3d.com/Documentation/ScriptReference/TreeInstance.html
To rotate the trees in the Terrain you will need to rotate them in the 3D modeling package.