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 Epifistu · Jun 08, 2012 at 01:46 PM · particle systemshuriken

Accessing Shuriken particle system values through a script in C#

Hello, I have massive problems accessing a particle system through a script.

What I want: a particle system that spawns particles continuously which then go in a line to the right. When dragging a GUI slider the speed or the size of the particles should change.

What I have: GUI slider is no problem,I also managed to create the particle system in the scene and it looks fine with the settings I gave it in the instructor. I called this particle system 'Spawner'. I also created a C# script called 'mosfetlogic' which I use to show the GUI slider and which should access the particle system. But this is where I get stuck and I cannot seem to find any useful tutorial/example to access it.

I do not need to access each particle on its own, just the basic values that I can change in the instructor. Right now I am really confused from all the different examples that I tried and didn't work so I don't even know where to start with the particle system.

Please help me if you have any clue, I am going crazy over this.

This is the code I have now, I want to use val to change values in the particle system:

 using UnityEngine;
 using System.Collections;

 public class mosfetlogic : MonoBehaviour {
     private float val, tVal, bVal;
     private Rect rect = new Rect(25, 25, 10, 300);

     // Use this for initialization
     void Start () {
         val = 1.0F;
         tVal = 3.0F;
         bVal = 0F;    
     }
         
     void OnGUI(){                                   
         val = GUI.VerticalSlider(rect, val, tVal, bVal);                  
     }    
 }
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
1

Answer by Berenger · Jun 08, 2012 at 03:22 PM

You need access to the particle System component. There is a property particleSystem (does it works ?) or GetComponent. Then, here are all the var you can access.

Comment
Add comment · Show 2 · 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 Berenger · Jun 08, 2012 at 05:40 PM 1
Share

Epifistu : Thank you very much but the problem is that I don't know how to access it. All I need would be an example code on how to change one of the values :S

$$anonymous$$e : Sure sure. The following script must be attached on the same GameObject than the particle system

 ParticleSystem ps;

 private void Start(){
     ps = GetComponent< ParticleSystem >();
 }

 private void OnGUI(){
     ps.emissionRate = GUI.VerticalSlider( ps.emissionRate, 0, 100 );
 }
avatar image Epifistu · Jun 08, 2012 at 05:52 PM 0
Share

This is wonderful, thank you very much it's exactly what I was looking for! :D

avatar image
0

Answer by Epifistu · Jun 08, 2012 at 04:14 PM

Thank you very much but the problem is that I don't know how to access it. All I need would be an example code on how to change one of the values :S

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 coding_crow · Oct 06, 2014 at 01:16 PM

In any script that is attached to the same GameObject as your shuriken, you can call transform.particleSystem for a shortcut. Then You can use particleSystem.GetParticles() and particleSystem.SetParticles(). Be warned though that the latter WILL cause a bug where your Shuriken will only render when its emitter is in view of the camera, thus causing individual particles to be culled while still in view.

 class MyClass : MonoBehaviour{
 
 ParticlesSystem shuriken;
 
 
 void Start()
 {
    shuriken = particleSystem;
    SetParticlesToFormALine();
 }
 
 void SetParticlesToFormALine()
 {
    ParticleSystem.Particle[] particles = new ParticleSystem.Particle[8];
    for(int particleCount = 0; particleCount  < 8; particleCount ++)
           {
           particles[particleCount ] = new ParticleSystem.Particle();
           particles[particleCount ].position = Vector3.right*i;
           particles[particleCount ].color = Color.White;
           particles[particleCount ].size = 1f;
 
           }
 
          shuriken.SetParticles(particles,particleCount);
 
 }
 
 

}

a very good tutorial on scripting shuriken: http://catlikecoding.com/unity/tutorials/graphs/

the culling bug: http://answers.unity3d.com/questions/218369/shuriken-particle-system-not-rendering-particles-w.html

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.

Follow this Question

Answers Answers and Comments

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Scripting Shuriken 1 Answer

The name 'Joystick' does not denote a valid type ('not found') 2 Answers

why is particle system duration read only? 2 Answers

How do I create a Shuriken moving particle system? 0 Answers

Changing sub emitter via script? 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