7

I have an update function that will check if something is equal to true and if it is equal to true it will run some code but then I want the whole script to be disabled. Please help, thanks!

1

3 Answers 3

13

You should use an enabled field. Try following

gameObject.GetComponent<EmailSender >().enabled = false;
Sign up to request clarification or add additional context in comments.

3 Comments

What do you mean, it doesn't work? What do you expect it to do and what does it do?
I want it to disable the script so it can't be used anymore.
@alexo1001 then you need to use yourGameObject.setActive(false);
0

This will work:

public GameObject otherobj;//your other object
public string scr;// your secound script name
void Start () {
    (otherobj. GetComponent(scr) as MonoBehaviour).enabled = false;
}

Comments

0

You can disable script component by using the following syntax,

GameObject.Find("Cube").GetComponent<MoveObject>().enabled = false;

Here I disable the MoveObject script from the object named Cube.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.