How do i access a SphereCollider added by RequireComponent?

Hi all

Im trying to access a SphereCollider that i added to my gameobject by using the RequireComponent. What i essentially want to do is set the colliders radius to my range variable as shown in the code below.

 using UnityEngine;
using System.Collections;
using System.Collections.Generic;

[RequireComponent (typeof (SphereCollider))]
public class tower : MonoBehaviour {

	public float towerRange;
	public float deployTime;
	public List<GameObject> towerTargets;

	// Use this for initialization
	void Start () {
		SphereCollider towerRangeCollider = this.GetComponent<SphereCollider>();
		towerRangeCollider.name = "Tower Range Collider";
		towerRangeCollider.radius = towerRange;
		towerTargets = new List<GameObject>();
	}
	
	// Update is called once per frame
	void Update () {

	}
	
	// Add enemies to the towers list of targets upon entering its range
	void OnTriggerEnter(Collider possibleTarget)
	{
		if (possibleTarget.tag == "Enemy" || possibleTarget.tag == "Friend")
		{
			towerTargets.Add(possibleTarget.gameObject);
			Debug.Log(possibleTarget.gameObject.name + " entered the trigger");
		}
	}
	
	// Remove enemies from the towers list of targets upon leaving its range
	void OnTriggerExit(Collider possibleTarget)
	{
		if (possibleTarget.tag == "Enemy" || possibleTarget.tag == "Friend")
		{
			for(int i = 0;i < towerTargets.Count; i++)
			{
				if(towerTargets*.gameObject.name == possibleTarget.gameObject.name)*
  •  		{*
    
  •  			towerTargets.RemoveAt(i);*
    
  •  			i--;*
    
  •  		}*
    
  •  	}*
    
  •  }*
    
  • }*
    }

Anywhere within a function in your Tower class you can access the SphereCollider by doing this:

SphereCollider sphereCollider = GetComponent<SphereCollider>();

You can use that in the start function to apply the radius.

To your side note question:

The OnTriggerExit will not be called at all because it has to be written with a upper case ‘O’ instead of a lower case ‘o’.

Also you should not remove objects from a List inside of a foreach through that same list, because the foreach will then fail on the potential next iteration in the list.
I usually do it like this if I need to remove from a list I am iterating through:

for(int i = 0; list.Count; i++)
{
    if(shouldBeRemoved)
    {
        list.RemoveAt(i);
        i--;
    }
}