D
D
Daniil Cherepanov2021-06-10 18:36:11
Unity
Daniil Cherepanov, 2021-06-10 18:36:11

Unity 2d, created an enemy and added particles to it, when colliding with an enemy, a new scene opens and the particles disappear abruptly, what should I do?

The game is similar to circle turn, particles were added to the enemy, when they collide with the hero, these particles appear accordingly, the hero dies and a new scene is loaded, so quickly that the particles are shown literally for a second, but I want the particles to remain on the new stage for a short time, like do it?
Here is the code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.SceneManagement;

public class JellyScript : MonoBehavior
{
public int score = 1;
public bool isMulti;
[SerializeField] Text scoreText;

public GameObject bonusEffect;
public GameObject deadeffect;

public void Start()
{
isMulti = PlayerPrefs.GetInt("isMulti") == 1 ? true : false;
}

private void OnTriggerEnter2D(Collider2D other)
{
if (other.gameObject.tag == "coin")
{
Destroy(other.gameObject);
Instantiate(bonusEffect, transform.position, Quaternion.identity);
if (isMulti)
score += 2;
else
score++;

if (isMulti)
score += 5;
else
score++;
}

if (other.gameObject.tag == "ghost")
{
Instantiate(deadeffect, transform.position, Quaternion.identity);
PlayerPrefs.SetInt("Score", score);
SceneManager.LoadScene(2);
}

}

private void Update()
{
scoreText.text = score.ToString();
}
}
deadeffect is enemy particles..

Answer the question

In order to leave comments, you need to log in

1 answer(s)
G
GavriKos, 2021-06-10
@GavriKos

Loading a scene completely clears the current scene. Or load additively and then clean by hand. Or change the logic in general.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question