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 SVKsuli · Jul 20, 2014 at 12:40 PM · gameobjectsetactiveactive

activate GameObject dont work

hi, i have problem with activate gameobject, i try use GameObject.active = true;, GameObject.SetActive(true); and nothing work but when i write it with false it work, why is it? here is code what i use:

 #pragma strict
  
 static var speed = 0;
 var particle : GameObject;
 
 function Start () {
 
 }
 
 function Update () {
     particleSystem.startSpeed = speed /20;
     if(speed == 0) {
         particle.SetActive(false);
     }
     else {
         particle.SetActive(true);
     }
 }
Comment
Add comment · Show 5
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 gjf · Jul 20, 2014 at 02:30 PM 0
Share

do you get any errors? if so, what are they?

have you set particle to contain a reference to the GameObject you're trying to affect?

btw, you can simplify your code:

 particle.SetActive((speed != 0));

ins$$anonymous$$d of the '`if`'

avatar image robertbu · Jul 20, 2014 at 02:49 PM 0
Share

Any chance that the game object assigned to 'particle' is the same game object this script is attached to? If so, you should note that deactivating a game object results in the scripts on that object no longer getting Update() calls.

Also note that the compiler is going to infer that speed is an int, so if speed has any value below 20, it will evaluate to 0.

avatar image SVKsuli · Jul 20, 2014 at 03:12 PM 0
Share

i dont know now what you think, it dont get eny errors, this particle object is empty gameobject with component particlesistem and this script and this gameobject is inserted to player... i try this:

pragma strict

 static var speed = 0;
 var particle : GameObject;
 
 function Start () {
 
 }
 
 function Update () {
     particleSystem.startSpeed = speed /20;
     particle.SetActive((speed != 0));
 }

i manually set deactivate this object and when i play game it do nothink. and yes speed can be 1500.

avatar image gjf · Jul 20, 2014 at 03:30 PM 0
Share

did you assign anything to the '`particle`' variable in the inspector?

avatar image SVKsuli · Jul 21, 2014 at 10:54 PM 0
Share

Thx for help all it work how Robertbu say... im idiot i dont see i disable gameobject with script then this script cant work and next when i disable gameobject game dont see it than i work it litle diferent:

 #pragma strict
  
 static var speed = 0;
  
 function Start () {
  
 }
  
 function Update () {
     particleSystem.startSpeed = speed /20;
     
     if(speed == 0) {
         GetComponent(ParticleSystemRenderer).enabled = false;
     }
     else {
         GetComponent(ParticleSystemRenderer).enabled = true;
     }
 }

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by revapps · Jul 20, 2014 at 03:27 PM

Remove the "else" statement. Instead, use "if".

 #pragma strict
  
 static var speed = 0;
 var particle : GameObject;
  
 function Start () {
  
 }
  
 function Update () {
     particleSystem.startSpeed = speed /20;
     if(speed == 0) {
         particle.SetActive(false);
     }
     if (speed > 0){
         particle.SetActive(true);
     }
 }
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 SVKsuli · Jul 20, 2014 at 03:31 PM 0
Share

nothink, this i try too. when i play game it automatic set to false but when i move it do nothink only i can manually set true but it dont work automatic.

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

SetActive(true) not working 2 Answers

GameObject.setActive(bool) is not activating my gameObject 1 Answer

Does inactive Objects eat up Performance? 1 Answer

The best overload for the method 'UnityEngine.GameObject.SetActive(boolean)' is not compatible with the argument list '()'. 1 Answer

How to swap gameObjects on the press of a button? 1 Answer


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