Cannot turn script back on

I've got an issue. When (Input.GetMouseButtonUp (0), Speedy script is disabled, thus we cannot enable it again from inside the script like shown below. How can we go around this?

public class  Speedy : MonoBehaviour {

GameObject car;

if (speed == good)
{
GameObject car = GameObject.FindWithTag ("Car");

if (Input.GetMouseButtonUp (0))
{
car.GetComponent<Speedy>().enabled = false;
}

else car.GetComponent<Speedy>().enabled = true;
}
}

• This is more an architecture issue than a problem with an if statement. Check for your mouse click outside Speedy, and activate or deactivate it from there. – Almo Jan 12 '16 at 20:36
• @Almo Title edited. – user77303 Jan 12 '16 at 20:36
• once you disabled script so how do you expect to run same script to enable it? which is now disable? – Hamza Hasan Jan 12 '16 at 20:39
• @HamzaHasan That's my question. Is there another way? – user77303 Jan 12 '16 at 20:40
• Control all of these operations from another class. – Hamza Hasan Jan 12 '16 at 20:43

For this, you can use FindObjectOfType either.

FindObjectOfType gives you reference on relevant script once then you can play with it.

If I edit your code, then it should be something like this

public class  Controller : MonoBehaviour {

Speedy car;

Start()
{
car = FindObjectOfType<Speedy>();
}

if (speed == good)
{

if (Input.GetMouseButtonUp (0))
{
car.enabled = false;
}

else car.enabled = true;
}

}


Drop this script to another GameObject in hierarchy.

NOTE: In your question you are disabling script from car but enabling if from cube. I don't know that you did it intentionally.