Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 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 ChocoboyYT · Apr 01, 2021 at 10:21 AM · particlesparticlesystem

How to make particles not disappear when called a second time

I'm trying to make a nice particle system that stays for a while, but the thing is, the particles disappear instantly once I call the particles again. How would I make the particles not disappear upon calling it again while not having to deal with prefabs and instantiation? This is my code script for moving the character:

 using System.ComponentModel;
 using System.Timers;
 using System;
 using System.Threading;
 using System.Runtime.InteropServices;
 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 using UnityEngine.ParticleSystemJobs;
 public class Move : MonoBehaviour
 {
     [SerializeField]
     private float speed;
     [SerializeField]
     private float dashSpeed;
     [SerializeField]
     private float dashInterval;
      [SerializeField]
     private int dashLength;
     [SerializeField]
     private bool jumps;
      [SerializeField]
     private bool dashes;
      [SerializeField]
     private bool maxDashes;
     [SerializeField]
     private int maxJumps;
     [SerializeField]
     private float jumpHeight;
     [SerializeField]
     private bool dashing = false;
     //[SerializeField]
     //private float jumpHeight1;
     //[SerializeField]
     //private float jumpHeight2;
     private Rigidbody2D rb2D;
     
     public GameOver gameOver;
     public ParticleSystem dashPart;
     public ParticleSystem landPart;
     public ParticleSystem deathPart;
     public Animator right;
     private Vector3 curPos;
     private Vector3 lastPos;
     public Sprite artDeath; 
     public Vector3 rotation;
 
     private void Start()
     {
         dashPart.Stop();
         rb2D = GetComponent<Rigidbody2D>();
     }
     private void Update()
     {
         transform.eulerAngles = rotation;
         if(dashing == false)
         {
             if(Input.GetKey("d"))
             {
                 rotation = new Vector3(0f, 0f, 0f);
                 transform.Translate(speed * Time.deltaTime, 0f, 0f);
             }
             if(Input.GetKey("a"))
             {
                 rotation = new Vector3(0f, 180f, 0f);
                 transform.Translate(speed * Time.deltaTime, 0f, 0f);
             }   
             if(Input.GetKeyDown("space"))
             {
                 if(jumps == true)
                 {
                     StartCoroutine(Jump());
                 }
             }
         }
         curPos = transform.position;
         if(curPos == lastPos) 
         {
             right.SetFloat("Move", -1f);
         }
         else
         {
             right.SetFloat("Move", 1f);
         }
         lastPos = curPos;
         
         if(Input.GetKeyDown("left shift"))
         {
             StartCoroutine(Dash());
         }
         
     }
     void OnTriggerStay2D(Collider2D other)
     {
          
         
             dashes = true;
         
     
         if(other.gameObject.CompareTag("Enemy"))
         {
             gameObject.GetComponent<Move>().enabled = false;
             right.SetFloat("Death", 1f);
             gameOver.GameEnd();
             
         }
     }   
     void OnTriggerEnter2D(Collider2D other)
     {
     
         float vel =  rb2D.velocity.y;
         int emitInt = Convert.ToInt32(vel);
         //Debug.Log(emitInt.ToString());
        
         if(other.gameObject.CompareTag("Ground"))
         {
             jumps = true;
             dashes = true;
             right.SetFloat("Jump", 0f);
             landPart.gameObject.GetComponent<PartMoove>().Move();
             landPart.emission.SetBursts(
             new ParticleSystem.Burst[]{
                 new ParticleSystem.Burst(0f, -emitInt * 2)
             });
             landPart.Play();
         }
         if(other.gameObject.CompareTag("Enemy"))
         {
             gameObject.GetComponent<Move>().enabled = false;
             right.SetFloat("Death", 1f);
             gameOver.GameEnd();
             
         }
     }   
     private void OnTriggerExit2D(Collider2D col) 
     {
         if(col.gameObject.CompareTag("Ground"))
         {
             jumps = false;
         }
     }
     IEnumerator Jump()
     {
         jumps = false;
         right.SetFloat("Jump", 1f);
         yield return new WaitForSeconds(0.2f);
         rb2D.AddForce(transform.up * jumpHeight);
         //transform.Translate(Vector3.up * jumpHeight * Time.deltaTime);
         //transform.position += Vector3.up * jumpHeight * Time.deltaTime;
     } 
     IEnumerator Dash()
     {
         if(dashes == true)
         {
             dashPart.Play();
             dashes = false;
             for(int i = dashLength; i > -1; i--)
             {
                 if(i <= 0)
                 {
                     dashPart.gameObject.GetComponent<PartMoove>().Move();
                     right.SetFloat("Dash", 0f);
                     rb2D.gravityScale = 1.3f;
                     dashing = false;
                     dashPart.Stop();
                     rb2D.constraints = RigidbodyConstraints2D.None;
                 }
                 else
                 {
                     dashPart.gameObject.GetComponent<PartMoove>().Move();
                     right.SetFloat("Dash", 1f);
                     dashing = true;
                     rb2D.gravityScale = .1f;
                     rb2D.constraints = RigidbodyConstraints2D.FreezePositionY;
                 }
                 yield return new WaitForSeconds(dashInterval);
                 transform.Translate(dashSpeed * Time.deltaTime, 0f, 0f);
             }
         }
     }
 }
 

script for moving particles to the player but not stick to it: using System.Collections; using System.Collections.Generic; using UnityEngine;

 public class PartMoove : MonoBehaviour
 {
     public Transform targetpart;
     public bool rotato;
     public float offsety;
     public void Move()
     {
         transform.position = new Vector3(targetpart.position.x,targetpart.position.y-offsety,targetpart.position.z);
         if(rotato == true)
         {
             if(targetpart.eulerAngles.y == 0f)
             {
                 transform.eulerAngles = new Vector3(0f,-90f,0f);
             }
             else if(targetpart.eulerAngles.y == 180)
             {
                 transform.eulerAngles = new Vector3(0f,-270f,0f);
             }
             
         }
         
     }
 }
 

Also, as a side note, does anyone know how to add friction to the particle collisions?

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

0 Replies

· Add your reply
  • Sort: 

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

117 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 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 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 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 avatar image avatar image avatar image avatar image avatar image

Related Questions

Emit Random Particles? 2 Answers

Unity 2D Particle System Interaction. 0 Answers

Glowing Particle 3 Answers

Finding Particle Information Upon Collision 2 Answers

Particle System not working. 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