How do I ignore units not visible in the camera?

Hi All,

I need help with the following code. I am learning how to code a unit selection box for an RTS game. I was following a tutorial by this guy:

His code is outdated however and I am stuck with the following issue. Code attached:

using UnityEngine;
using System.Collections;

public class Unit : MonoBehaviour
{
    public bool selected = false;
    public Renderer rendUnit;

    void start()
    {
        rendUnit = GetComponent<Renderer>();
    }

    void Update()
    {
        if (rendUnit.isVisible && Input.GetMouseButtonUp (0)) //if LMB is released and unit is visible on screen
        {
            Vector3 camPos = Camera.main.WorldToScreenPoint(transform.position);
            camPos.y = Select.InvertMouseY(camPos.y);
            selected = Select.selection.Contains(camPos);
        }
        if (selected)
            rendUnit.material.color = Color.red;
        else
            rendUnit.material.color = Color.white;
    }
}

So I think he was trying to ignore the units outside of camera view when selecting but in my modified code the renderer class is not referencing any object, thus giving an error. Any idea how to fix this?

Start

not

start