Is there a way I can set a transform to all the terrain trees? I have 1 script and I cannot put all my trees in there. Here it is:
#pragma strict
var SpawnObject : GameObject;
var SpawnPoint : GameObject;
var Tree : Transform;
var SpawnDistance = 1.7f;
private var canSpawn = false;
private var dist = 9999f;
function Update () {
dist = Vector3.Distance(Tree.transform.position, transform.position);
if(dist <= SpawnDistance) {
if(Input.GetButtonDown("Fire1"))
{
Instantiate(this.SpawnObject, this.SpawnPoint.transform.position, this.SpawnPoint.transform.rotation);
}
}
}
function OnDrawGizmosSelected ()
{
Gizmos.color = Color.yellow;
Gizmos.DrawWireSphere (transform.position, SpawnDistance);
}
function OnGUI() {
if(dist <= SpawnDistance) {
if (transform.name.Length <= 7)
{
GUI.Box (Rect (Screen.width*0.5-(165*0.5), 100, 165, 22), "Click to chop tree.");
}
else
{
GUI.Box (Rect (Screen.width*0.5-(185*0.5), 100, 185, 22), "Click to chop tree.");
}
}
}