• 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 rajavamsidhar_gvs · Aug 13, 2015 at 05:25 AM · instantiategetcomponentdisableenable

[solved]how can i enable or disable a component of instantiated objects?

i've a couple of gameobjects to instantiate with dragmouse script.i instantiate a few gameobjects.then ive a toggle for enableing that dragmouse script of instantiated.but its not working properly.

Now my question is how can i disable or enable that script of instantiated with toggle.how can i use find()? how can i achieve it please help me out.

Comment
Add comment · Show 1
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 rajavamsidhar_gvs · Aug 13, 2015 at 09:41 AM 0
Share

i got my solution finally. thanks guys for your support. i'm unable to post this as answer.tell me how to do this question as solved. here is the code.

 GameObject array;
 
 //trigger condition
 array=GameObject.FindObjectsWithTag("Tag");
 for(int i =0;i<array.Length;i++)
 array[i].GetComponent<Drag$$anonymous$$ouse>().enabled=false;//or true.
 
 //solved

5 Replies

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

Answer by rajavamsidhar_gvs · Aug 13, 2015 at 07:43 AM

Thanks everyone. Actually my need is i'll instantiate gameobjects which have dragmouse script but initially that script is disabled by manually.next ive a toggle for enable that script..i tried all what you have mentioned in answers.But here is i've a script for instantiating objects like cube,sphere. and in another script one toggle is there. if it is true script will enable and i'll change the position of particular gameobject with mouse.but it is working sometime but its not disabling all time. i added tag "Drag" for all my gameobjects which are going to instantiate.

so i want all gameobjects who have drag tag. then i'll use getcomponent().enabled=false/true. i tried with GameObject.FindWithTag. but i'm getting only first object. a want all in on array. Again Thanks for your effort.

Edit

i got my solution finally. thanks guys for your support. i'm unable to post this as answer.tell me how to do this question as solved. here is the code.

GameObject array;

//trigger condition array=GameObject.FindObjectsWithTag("Tag"); for(int i =0;i().enabled=false;//or true.

//solved

Comment
Add comment · Show 4 · 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 MixPix · Aug 13, 2015 at 07:53 AM 0
Share

Ins$$anonymous$$d of GamObject.FindWithTag, do GameObject.FindObjectsWithTag(), and then cycle through that array :)

avatar image rajavamsidhar_gvs · Aug 13, 2015 at 08:46 AM 0
Share

i'm not much good in coding.still i'm trying.but i'm not getting proper solution.

avatar image GiyomuGames · Aug 13, 2015 at 08:47 AM 0
Share

Show us the code you have now, it'll be easier to help you.

avatar image rajavamsidhar_gvs · Aug 13, 2015 at 09:43 AM 0
Share

i achieved solution.thanks all..

avatar image
0

Answer by itsharshdeep · Aug 13, 2015 at 07:03 AM

Can you pls explain that How/Which gameObject's script you want to disable .. ( i.e. How you can decide that now this or that one gameObject should disable the 'dragmouse' script).

If you need the last one then the following code can work

  GameObject currentLoadedModel;
     currentLoadedModel = Instantiate (objTemp) as GameObject;
     currentLoadedModel.GetComponent<dragmouse>().enabled  = false;
 
Comment
Add comment · Show 1 · 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 rajavamsidhar_gvs · Aug 13, 2015 at 10:00 AM 0
Share

i solved it. see my comment for my question.Thanks for support. :)

avatar image
0

Answer by GiyomuGames · Aug 13, 2015 at 06:20 AM

I'm not sure I understand your question, but just in case:

 GetComponent<YourScriptName>().enable = true/false

allows you to enable / disable a component.

Comment
Add comment · 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
0

Answer by Priyanshu · Aug 13, 2015 at 07:05 AM

  1. Instantiate Object.

  2. Get its component.

  3. Disable it.

Instantiate( yourGameObject).GetComponent().enabled = false;

Comment
Add comment · 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
0

Answer by manel1 · Aug 13, 2015 at 09:09 AM

GameObject GameObjectName;

GameObjectName=GameObject.FindWithTag("TagName");

GameObjectName.GetComponent().enabled=false;

Comment
Add comment · 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

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

28 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Disable SCRIPT HELP!!!! 1 Answer

Disable a GameObjects scripts knowing only the GameObjects name 3 Answers

Do empty transforms take up much CPU power? 1 Answer

How do I acces a specific GameObject within the terrain???? 1 Answer

Disable all instances of a component 2 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