Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by Earth-O-Matic · Apr 16, 2011 at 08:10 PM · disabledynamicenabletypebce0019

enable / disable a script without dynamic typing

I'm trying to move my project over to my mac laptop and unity iOS and have unearthed a number of issues due to dynamic typing. I have gotten rid of most but am left with a few outstanding issues this being one of them.

At one point I am trying to reference a script to disable it so I don't get any interference from it during another part of the game. Here is a code snip.

  if (GUI.Button (position5, plankPhy, style5))
        if (Physics.Raycast (ray, hit, 300)) {
            Instantiate(PhyPlank, hit.point, Quaternion.identity);
            GetComponentInChildren(ClickSpawn).enabled = false;
            Time.timeScale = .0000001;

This works great when playing for PC or web but as soon as I put it on my iOS build (or in this case throw "#pragma strict" at the top of my code for working on my pc I get an error...

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

What's happening in the script is when an object the player moves and places down in the map is spawned it freezes time to allow the player to place the object but it also disables a script that generates geo when the mouse button is clicked.

There is a second part to the script that references the script again to enable it again. Any help as always is very much appreciated. Thank you!

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

2 Replies

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by Earth-O-Matic · Apr 16, 2011 at 09:43 PM

Alright figured it out!

So to get the code to disable it without dynamic typing (needed for iOS) It needs to be written long hand like this:

GameObject.Find("TheGameObjectWithYourScript");
(GetComponent(YourScript) as YourScript).enabled = false;

once it's been disabled. on the next set of script to enable it again (I'm assuming since it has been called - I'm new at this so shrug) you define the game object in a var and in my case using mouse up it would look something like this:

var clickItem : GameObject;

function OnMouseUp(){

  (clickItem.GetComponent(YourScript) as YourScript).enabled = true;

}

So this is how it works for me to call a script to enable and disable it without dynamic typing.

Comment
Add comment · Show 3 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Earth-O-Matic · Apr 16, 2011 at 09:44 PM 0
Share

By the way, the enable and disable are on two separate scrips for my project which is why I need to define twice.

avatar image Uzquiano · Apr 16, 2011 at 09:48 PM 0
Share

So you had to Find()... as I suggest you...

avatar image Bunny83 · Apr 16, 2011 at 10:43 PM 0
Share

roll eyes... remove the GameObject.Find line.... it has no use in your script. The semicolon ter$$anonymous$$ates the statement. Your GameObject.Find line doesn't belong to the second line in any way...

avatar image
0

Answer by Bunny83 · Apr 16, 2011 at 09:41 PM

You have to cast the Component reference you get back from GetComponent into the right type, or just use the generic function.

GetComponentInChildren.<ClickSpawn>().enabled = false;

or the old casting way:

(GetComponentInChildren(ClickSpawn) as ClickSpawn).enabled = false;
Comment
Add comment · Show 3 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Eric5h5 · Apr 16, 2011 at 11:35 PM 0
Share

Why was this downvoted? It's correct.

avatar image Bunny83 · Apr 16, 2011 at 11:39 PM 0
Share

I guess Uzquiano don't like me :D but not sure ...

avatar image Uzquiano · Apr 17, 2011 at 03:19 PM 0
Share

??? Anyway, if you mean for the discussion below, I am newer than you in using Unity but I think ins$$anonymous$$d of saying always that using Find() is kind of sin, it must be said that that Find() must be used only inside Awake() and Start(). I think that there are more memory inefficient behaiviours that people care less and affect more.

Your answer

Hint: You can notify a user about this post by typing @username

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

Answers Answers and Comments

No one has followed this question yet.

Related Questions

Enable and disabled parent contraint with c# 1 Answer

Enable/Disable GameObject Button script 1 Answer

Enabling / Disabling C# Scripts - Why am I getting the error "not a member of 'UnityEngine.Component'"? 1 Answer

Disable gameobject at other screen with code ? 0 Answers

Unable to enable script 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges