Turning Scripts on/off?

Right, I'm just about finished with one of my main game mechanics..

I have 2 different scripts

1 = SeekSteer 2 = SmoothFollow2

Ideally I want to switch between these two scripts. I have the scripts attached to a game object. Initially SeekSteer is ticked inside the inspector, and on running the game, it uses this script. I can then pause the game, untick SeekSteer, Tick SmoothFollow2, unpause, and the gameobject uses this script instead.

So what I want to do is replicate this process in the game, say on a keypress. Is this possible?

Here are my scripts.

using UnityEngine;
using System.Collections;

public class SeekSteer : MonoBehaviour
{

    public Transform[] waypoints;
    public float waypointRadius = 1.5f;
    public float damping = 0.1f;
    public bool loop = false;
    public float speed = 2.0f;
    public bool faceHeading = true;

    private Vector3 currentHeading,targetHeading;
    private int targetwaypoint;
    private Transform xform;
    private bool useRigidbody;
    private Rigidbody rigidmember;   

    // Use this for initialization
    protected void Start ()
    {
        xform = transform;
        currentHeading = xform.forward;
        if(waypoints.Length<=0)
        {
            Debug.Log("No waypoints on "+name);
            enabled = false;
        }
        targetwaypoint = 0;
        if(rigidbody!=null)
        {
            useRigidbody = true;
            rigidmember = rigidbody;
        }
        else
        {
            useRigidbody = false;
        }
    }

     // calculates a new heading
    protected void FixedUpdate ()
    {
        targetHeading = waypoints[targetwaypoint].position - xform.position;

        currentHeading = Vector3.Lerp(currentHeading,targetHeading,damping*Time.deltaTime);
    }

    // moves us along current heading
    protected void Update()
    {
        if(useRigidbody)
            rigidmember.velocity = currentHeading * speed;
        else
            xform.position +=currentHeading * Time.deltaTime * speed;
        if(faceHeading)
            xform.LookAt(xform.position+currentHeading);

        if(Vector3.Distance(xform.position,waypoints[targetwaypoint].position)<=waypointRadius)
        {
            targetwaypoint++;
            if(targetwaypoint>=waypoints.Length)
            {
                targetwaypoint = 0;
                if(!loop)
                    enabled = false;
            }
        }
    }

     // draws red line from waypoint to waypoint
    public void OnDrawGizmos()
    {
        Gizmos.color = Color.red;
        for(int i=0;i< waypoints.Length;i++)
        {
            Vector3 pos = waypoints*.position;*
 *if(i>0)*
 *{*
 *Vector3 prev = waypoints[i-1].position;*
 *Gizmos.DrawLine(prev,pos);*
 *}*
 *}*
 *}*
*}*
*using UnityEngine;*
*using System.Collections;*
*public class SmoothFollow2 : MonoBehaviour {*
 *public Transform target;*
 *public float distance = 3.0f;*
 *public float height = 3.0f;*
 *public float damping = 5.0f;*
 *public bool smoothRotation = true;*
 *public float rotationDamping = 10.0f;*
 *void Update () {*
 *	    Vector3 wantedPosition = target.TransformPoint(0, height, -distance);*
_	    transform.position = Vector3.Lerp (transform.position, wantedPosition, Time.deltaTime * damping);_
*	    if (smoothRotation) {*
*	    	    Quaternion wantedRotation = Quaternion.LookRotation(target.position - transform.position, target.up);*
_		    transform.rotation = Quaternion.Slerp (transform.rotation, wantedRotation, Time.deltaTime * rotationDamping);_
*	    }*
*	    else transform.LookAt (target, target.up);*
 *}*
*}*
*```*
*<p>Thanks so much for the suggestions so far, it's really really helped me in learning the core aspects of scripting within unity!</p>*

Yes, it's possible. The 'enabled' property of Monobehaviours controls whether they recieve the Update events, so you simply need to set the enabled of one script to 'true' and the other script to 'false'.

http://unity3d.com/support/documentation/ScriptReference/Behaviour-enabled.html

For more information about how to get references to your particular instances of SeekSteer and SmoothFollow, see Accessing Other Objects, and Accessing Other Components in the manual.

Just for reference.

I added the following script and attached it to the same game object

var switchTarget = false;

function Update () {
if(switchTarget)

	{
		GetComponent("SeekSteer").enabled = false;
		GetComponent("Follow").enabled = true;
	}

else

	{
		GetComponent("SeekSteer").enabled = true;
		GetComponent("Follow").enabled = false;

	}

if(Input.GetKeyDown("l"))
{
		switchTarget = true;
}

}

Thank you for the response, and thank you for every user that has helped me with this project so far, really appreciate it.

reformatted the script so it’s easier to use:

var switchTarget = false; 
    function Update () { if(switchTarget)
    	{
    		GetComponent("SeekSteer").enabled = false;
    		GetComponent("Follow").enabled = true;
    	}
    else
    
    	{
    		GetComponent("SeekSteer").enabled = true;     
    		GetComponent("Follow").enabled = false;} 
    
    if(Input.GetKeyDown("l")) { switchTarget = true; }
    }