I NEED HELP, IM GOING INSANE JUST FOR PARTICLE SYSTEM… everything work fine if i can turn on the send collision message every summoned particle… BUT THE DOCUMENTATION JUST SHOWED THIS public bool sendCollisionMessages;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerHealth : MonoBehaviour
{
[SerializeField]
GameObject GameOverUI;
int hitCount = 0;
private void OnParticleCollision(GameObject particle)
{
hitCount++;
if (hitCount == 3)
{
Time.timeScale = 0f; // Freeze the game
GameOverUI.SetActive(true);
}
}
}
this code work but with manual inputed particle system
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class BulletHellSpawner : MonoBehaviour
{
public int number_of_columns;
public float speed;
public Sprite texture;
public Color color;
public float lifetime;
public float firerate;
public float size;
private float angle;
public Material material;
public float spin_speed;
private float time;
public ParticleSystem system;
public LayerMask player;
private void Awake()
{
Summon();
}
private void FixedUpdate()
{
time += Time.fixedDeltaTime;
transform.rotation = Quaternion.Euler(0, 0, time * spin_speed);
}
void Summon()
{
angle = 360f / number_of_columns;
for (int i = 0; i < number_of_columns; i++)
{
Material particleMaterial = material;
var go = new GameObject("Bullet");
go.tag = "bullet";
go.transform.Rotate(angle * i, 90, 0);
go.transform.parent = this.transform;
go.transform.position = this.transform.position;
system = go.AddComponent<ParticleSystem>();
go.GetComponent<ParticleSystemRenderer>().material = particleMaterial;
var mainModule = system.main;
mainModule.startColor = Color.green;
mainModule.startSize = 0.5f;
mainModule.startSpeed = speed;
mainModule.maxParticles = 100000;
mainModule.simulationSpace = ParticleSystemSimulationSpace.World;
var emission = system.emission;
emission.enabled = false;
var shapeModule = system.shape;
shapeModule.enabled = true;
shapeModule.shapeType = ParticleSystemShapeType.Sprite;
var textureSheetModule = system.textureSheetAnimation;
textureSheetModule.enabled = true;
textureSheetModule.mode = ParticleSystemAnimationMode.Sprites;
textureSheetModule.AddSprite(texture);
var collision = system.collision;
collision.enabled = true;
collision.type = ParticleSystemCollisionType.World;
collision.mode = ParticleSystemCollisionMode.Collision2D;
collision.lifetimeLoss = 1;
collision.collidesWith = player;
}
InvokeRepeating("DoEmit", 0f, firerate);
}
void DoEmit()
{
foreach (Transform child in transform)
{
system = child.GetComponent<ParticleSystem>();
var emitParams = new ParticleSystem.EmitParams();
emitParams.startColor = color;
emitParams.startSize = size;
emitParams.startLifetime = lifetime;
system.Emit(emitParams, 10);
}
}
}
but i want that every time summoned particle will have send collision message checked
collision.sendCollisionMessages = true;