x


how to disable a script in another script ?

if(showPage1==false) {

gameObject.Find("webpage1").GetComponent("WebViewTextureSample").enabled=false;

} WebViewTextureSample is a script of a plane error:

'enabled' is not a member of 'UnityEngine.Component'.

how can i solve it?

more ▼

asked Aug 14 '12 at 12:05 PM

HsmBoy gravatar image

HsmBoy
3

(comments are locked)
10|3000 characters needed characters left

2 answers: sort voted first

Replace the 'gameObject.Find("webpage1").GetComponent("WebViewTextureSample").enabled = false' line of code with this code:

var webScript : WebViewTextureSample;

webScript = gameObject.Find("webpage1").GetComponent("WebViewTextureSample");

webScript.enabled = false;
more ▼

answered Aug 14 '12 at 01:56 PM

TheVectorHunter gravatar image

TheVectorHunter
536 3

The reason why this works is because '.enabled' is a member of the custom type(Script) created in my code, and UnityEngine.Component does not have the member '.enabled' so it tosses the error.

Aug 14 '12 at 01:59 PM TheVectorHunter

Please accept my answer and vote it up if this solved your problem. I am willing to explain why the problem occured if you want.

Aug 14 '12 at 02:01 PM TheVectorHunter

thank you very much,it worked

Aug 16 '12 at 01:05 AM HsmBoy

Can you accept the answer and vote it up?

Aug 16 '12 at 08:43 PM TheVectorHunter

I'd like to ,but I don't know where to vote it up,I'm a newer i'm really sorry.

Aug 17 '12 at 06:42 AM HsmBoy
(comments are locked)
10|3000 characters needed characters left

Don't use quotes in GetComponent unless you really need to (which is almost never).

gameObject.Find("webpage1").GetComponent(WebViewTextureSample).enabled=false;

Using quotes makes it return Component, which you don't want.

more ▼

answered Aug 16 '12 at 09:14 PM

Eric5h5 gravatar image

Eric5h5
80.2k 41 132 519

(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x3328

asked: Aug 14 '12 at 12:05 PM

Seen: 154 times

Last Updated: Aug 17 '12 at 01:35 PM