Control child object for each copy

I have this code to fade a object when it gets far from the camera. It is a fern object with a plane child object. The script is on the fern object. It works fine for one object, but if I copy the object, only the first one fades. How can I access the game object “plane” for each fern and fade them individually? Here is the code:

using UnityEngine;
using System.Collections;
public class DisapearDistance : MonoBehaviour 
{
 public float far_distance = 10.0f;
 public float near_distance = 5.0f;
 private Transform cam;
 private GameObject plane_obj;
 private float dist_to_cam;
 private Color fade;
 private float color_alpha;

 void Start () 
 {
 cam = GameObject.FindGameObjectWithTag(Tags.camera).transform;
 plane_obj = GameObject.Find("plane");
 fade = plane_obj.renderer.material.color;
 }
 void Update()
 {
 dist_to_cam = Vector3.Distance(cam.transform.position, transform.position);
 if(dist_to_cam > far_distance)
 {
 plane_obj.SetActive (false);
 }
 else if(dist_to_cam > near_distance)
 {
 plane_obj.SetActive (true);
 color_alpha = 1 - ((dist_to_cam - near_distance) / (far_distance - near_distance));
 fade = new Vector4(fade.r, fade.g, fade.b, color_alpha);
 plane_obj.renderer.material.color = fade;
 }
 }
}

Thanks.

Your code is finding one instance of “plane” from the whole scene.

If your script is on each fern you need to find the instance of “plane” that is a child of this fern.

foreach (Transform child in transform)
{
if(child.name == “plane”)
{
plane_obj = child.gameObject;
}
}

This is exactly what I was looking for. In unity, the “transform” is kind of a way to select objects. Interesting.

Thanks a lot.