Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 Ekta-Mehta-D · May 17, 2013 at 07:41 AM · enable

Make Script Disable

Hello ..

I have one script which is repeatedly instantiating game object..

But after some condition match, i want to disable that script along with that object..

Script Code :

 #pragma strict
 public var enemy1Prefab : GameObject;
 
 private var x : float;
 private var y : float;
 private var z : float;
 
 private var scoreControllerScript : ScoreController;
 private var gameControllerScript : GameController;
 
 function Start () {
 
         gameControllerScript = GameObject.Find("Main Camera").GetComponent("GameController");
         scoreControllerScript = GameObject.Find("Main Camera").GetComponent("ScoreController");  
         InvokeRepeating("CreateRandomShip",0.01f,1.0f);
 }
 
 function Update () {
 
 }
 
 function CreateRandomShip()
 {
         x = Random.Range(-4.00f , 4.00f);
         z = -6.72f;
         y = 8.0f;
         enemy1Prefab.transform.position = new Vector3(x , y , z);    
         Instantiate(enemy1Prefab,enemy1Prefab.transform.position,enemy1Prefab.transform.rotation);
         
         if(gameControllerScript.gameStarted)
             scoreControllerScript.ManageEnimies();
 } 

And Code which i have written to Disable Object and script is here :

 if(GameObject.Find("Level6").active)
             {
                 Debug.Log("level 6");
                 enemy1CreationScript = GameObject.Find("Level6").GetComponent("Enemy1Creation"); 
                 enemy1CreationScript.enabled = false;
                 GameObject.Find("Level6").active = !GameObject.Find("Level6").active;
             }

By this code., My object and script both become disabled. I have Checked in Inspector panel..but then also it continuous to generate game object..

So what can be the reason behind this? Please Help me to solve out this issue..

Thanks for Your Support and Help..

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

3 Replies

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

Answer by vontio · May 17, 2013 at 09:27 AM

CancelInvoke("CreateRandomShip");

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 Ekta-Mehta-D · May 17, 2013 at 09:37 AM 0
Share

Thanx @vonito.. Your solution works..

avatar image
1

Answer by pl_bota95 · May 17, 2013 at 07:44 AM

Use GameObject.Find("your object").SetActive(true/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 Ekta-Mehta-D · May 17, 2013 at 07:50 AM 0
Share

SetActive() is not allowed..

avatar image
0

Answer by Dreamora · May 17, 2013 at 09:11 AM

Enabling or disabling scripts only impacts the automatic continous functions: Start, Update, LateUpdate, FixedUpdate

All the rest will continue to work independent on if the script is active or not. To disable that you will need to disable the script.gameObject.SetActive(...)

if setactive mentions its not allowed, you are on Unity 3.x and not 4x in which case its just .active

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 Ekta-Mehta-D · May 17, 2013 at 09:22 AM 0
Share

@Dreamora sir.. have used your idea.. but still it continuous to generate game object.. Now What Shoild i do ?? :(

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

16 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

Related Questions

Disable a GameObjects scripts knowing only the GameObjects name 3 Answers

Can a script enable components? 2 Answers

A node in a childnode? 1 Answer

Errors with gravity switching... 1 Answer

Best way to access a script component without knowing it's name? 4 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