Switch Script on Game object

hey i have a question i have a weapon that fires that works the weapom got spawnpoints for the bullets and fire effects that work on lets say script 1. Script 1 got an auto fire code. and i have a other script for rapit fire lets call taht Script 2. This script also works on a java code to get one bullet when Fire1 is getbuttondown.

Now to make my pointclear i how do i make a Script that switches from Script 1 To Script 2 When i GetButtonDown("X");

Basicly i want a script to Switch Scripts

and how do i do this by putting the script on the GameObject SpawnPoint?.Where my Script 1 is now or do i need to make an other Gameobject spawnpoint at the same point in 3d?? please help me I need this:p tnx

this don`t work?? i dont know mutch of scripting whats wrong with the code

the real name of script 1 is Shoot the real name of script 2 is RapitShoot

here`s my copy`d code i have removed somthing becous unity seems to crash on t won`t let me play.

The Script

function Update() { if( Input.GetKey("X") ) { if(Shoot.enabled) { Shoot.enabled = false; RapitShoot.enabled; } else { RapitShoot.enabled = false; Shoot.enabled; } } }

var script1 : ScriptName;
script1 = gameObject.GetComponent(“Script1”);

var script2 : ScriptName;
script2 = gameObject.GetComponent("Script2");

function Update()
{
    if( Input.GetKey("X") )
    {
        if(script1.enabled)
        {
            script1.enabled = false;
            script2.enabled = true;
        }
        else
        {
            script2.enabled = false;
            script1.enabled = true;
        }
    }
}

This True!!

Add both scripts to the main player, then add another script, and make this one get the components (scripts), and so then have a code like this:

var script1 : ScriptName;
script1 = gameObject.GetComponent("Script1");

var script2 : ScriptName;
script2 = gameObject.GetComponent("Script2");

function Update()
{
    if( Input.GetKey("X") )
    {
        if(script1.enabled)
        {
            script1.enabled = false;
            script2.enabled;
        }
        else
        {
            script2.enabled = false;
            script1.enabled;
        }
    }
}

Did this here, didn't test, but you should get the point.

Good luck =).

Above answers both work I agree, but are both kinda wrong in my humble, you CAN swap scripts.
but it’s quite hard (actually, not that hard come to think of it).
You’d GetComponent on one script, and copy it’s params if needed to an added component of your choice.
Something like this: (Sorry, c# only for me)

Script1 vScript1=gameobject.GetComponent<Script1>();
int ammo=vScript.Ammo;
GameObject vFlare=vScript.muzzleflare;
Destroy(vScript1);
Script2 vScript2=gameObject.AddComponent<Script2>();
vScript2.ammo=ammo;
vScript2.muzzleflare=vFlare;

It feels cleaner to me than redefining variables twice and mucking about with enabled.