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 davidflynn2 · Jul 15, 2013 at 06:22 PM · c#particle

Turn weather on and off

I have been working on the following script to allow me to click on a grid in my game and check the tag of it, If it has the tag world blocks it does something to only that block. What I am trying to do now it make it so when you click on a block it turns on or off the particlesystem that is childed to it. I have the particle childed to the block. I am not sure how to make it so when you click it checks if it is on or off and and switches the state of it.

This is my updated script I have so far it is getting close to what I need just cant get all fixed.

Here is the script:

 using UnityEngine;
 using System.Collections;
 
 public class ChangeWeather : MonoBehaviour
 {
     public bool active = true;
     private Transform child;
     
 
     void Update () 
     {
         if(Input.GetMouseButtonDown(0))
         {
              Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
                 RaycastHit hit;
             
             if(Physics.Raycast(ray, out hit))
             {
                 if(hit.collider.tag == "WorldBlocks")
                 {
                     
                     if(active == true)
                     {
                                              
                         foreach(Transform child in hit.transform) 
                         {
                                 child.Active = false;//This part is not working.
                         }
 
 
                         active = false;
                     }
                     
                     if(active == false)
                     {
                         foreach(Transform child in hit.transform) 
                         {
                                // child.Active = false; This part is not working
                         }
                         active = 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 davidflynn2 · Jul 15, 2013 at 06:27 PM 0
Share

So what I am wanting to do is get the child of the clicked game object and turn it off or on. I have named the gameObject weather.

avatar image robertbu · Jul 15, 2013 at 06:38 PM 1
Share

Do you have the particle system attached to the game object that is being clicked or on a child game object?

avatar image davidflynn2 · Jul 15, 2013 at 06:54 PM 0
Share

The child game object is a Shrunken particle system. So its the child I am wanting turned off and on.

avatar image rowdyp · Jul 15, 2013 at 07:01 PM 1
Share

well to make it simple, you could create a variable for the particle emitter and simple disable it or enable it when button is clicked

avatar image davidflynn2 · Jul 15, 2013 at 07:56 PM 0
Share

All I need is to find the child of clicked gameobject and disable its child.

2 Replies

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

Answer by davidflynn2 · Jul 15, 2013 at 08:52 PM

I ended up having to redo a lot of different things but this is what I got to work:

 if(hit.collider.tag == "WorldBlocks")
                 {
                     
                     if(active == true)
                     {
                                              
                         foreach(Transform child in hit.transform) 
                         {
                                child.renderer.enabled = true;
                         }
 
 
                         active = 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 robertbu · Jul 15, 2013 at 07:03 PM

A Particle System is not a game object...it is a Component. So if you attached the component to the same game object that is being clicked you can do:

 ParticleSystem ps = hit.collider.gameObject.particleSystem;

 if (ps.isPlaying)
         ps.Stop();
 else
         ps.Play();
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 davidflynn2 · Jul 15, 2013 at 07:09 PM 0
Share

If I add the particle system to my current game object is there any way of moving the particle system up so it falls down onto the object I am trying to make it snow.

avatar image creighcl · Jul 15, 2013 at 08:34 PM 1
Share

so you have the particle system attached to an empty game object and that object is a child of the block you're clicking? If so, you can still use Robert's answer. just do child.particleSystem.Stop();

avatar image robertbu · Jul 15, 2013 at 08:55 PM 0
Share

If the Particle Systems is attached to a child, you need to first gain access to that child. You can use drag and drop onto a variable at edit time, or you could use Transform.Find(). If your child was named 'Snow', it would be:

 GameObject goChild = hit.transform.Find("Snow");
 ParticleSystem ps = goChild.particleSystem;
  
 if (ps.isPlaying)
         ps.Stop();
 else
         ps.Play();

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

17 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

Related Questions

Multiple Cars not working 1 Answer

Distribute terrain in zones 3 Answers

Particle memory overhead 1 Answer

Can't get a coroutine to work as expected. 2 Answers

Getting XP when dies Help 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