Version: 2017.3 (switch to 2017.4)
LanguageEnglish
  • C#
  • JS

Script language

Select your preferred scripting language. All code snippets will be displayed in this language.

ParticleSystem.CollisionModule.collidesWith

Suggest a change

Success!

Thank you for helping us improve the quality of Unity Documentation. Although we cannot accept all submissions, we do read each suggested change from our users and will make updates where applicable.

Close

Submission failed

For some reason your suggested change could not be submitted. Please <a>try again</a> in a few minutes. And thank you for taking the time to help us improve the quality of Unity Documentation.

Close

Cancel

Switch to Manual
public var collidesWith: LayerMask;
public LayerMask collidesWith;

Description

Control which layers this particle system collides with.

See Also: LayerMask.

#pragma strict
private var ps: ParticleSystem;
public var layerToggle: boolean;
private readonly var layer0: int = 0;
private readonly var layer1: int = 1;
function Start() {
	ps = GetComponent.<ParticleSystem>();
	var main: var = ps.main;
	main.startColor = Color.red;
	var shape: var = ps.shape;
	shape.shapeType = ParticleSystemShapeType.Sphere;
	var collision: var = ps.collision;
	collision.enabled = true;
	collision.type = ParticleSystemCollisionType.World;
	collision.mode = ParticleSystemCollisionMode.Collision3D;
	collision.bounce = 0.0f;
	var collider1: var = GameObject.CreatePrimitive(PrimitiveType.Sphere);
	collider1.transform.parent = ps.transform;
	collider1.transform.localPosition = new Vector3(0.0f, 0.0f, 13.0f);
	collider1.transform.localScale = new Vector3(20.0f, 20.0f, 20.0f);
	collider1.layer = layer0;
	var collider2: var = GameObject.CreatePrimitive(PrimitiveType.Sphere);
	collider2.transform.parent = ps.transform;
	collider2.transform.localPosition = new Vector3(0.0f, 0.0f, -13.0f);
	collider2.transform.localScale = new Vector3(20.0f, 20.0f, 20.0f);
	collider2.layer = layer1;
}
function Update() {
	var collision: var = ps.collision;
	collision.collidesWith = layerToggle ? (1 << layer0) : (1 << layer1);
}
function OnGUI() {
	layerToggle = GUI.Toggle(new Rect(25, 40, 100, 30), layerToggle, "Toggle Layer");
}
using UnityEngine;
using System.Collections;

public class ExampleClass : MonoBehaviour { private ParticleSystem ps; public bool layerToggle; private readonly int layer0 = 0; private readonly int layer1 = 1;

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

var main = ps.main; main.startColor = Color.red;

var shape = ps.shape; shape.shapeType = ParticleSystemShapeType.Sphere;

var collision = ps.collision; collision.enabled = true; collision.type = ParticleSystemCollisionType.World; collision.mode = ParticleSystemCollisionMode.Collision3D; collision.bounce = 0.0f;

var collider1 = GameObject.CreatePrimitive(PrimitiveType.Sphere); collider1.transform.parent = ps.transform; collider1.transform.localPosition = new Vector3(0.0f, 0.0f, 13.0f); collider1.transform.localScale = new Vector3(20.0f, 20.0f, 20.0f); collider1.layer = layer0;

var collider2 = GameObject.CreatePrimitive(PrimitiveType.Sphere); collider2.transform.parent = ps.transform; collider2.transform.localPosition = new Vector3(0.0f, 0.0f, -13.0f); collider2.transform.localScale = new Vector3(20.0f, 20.0f, 20.0f); collider2.layer = layer1; }

void Update() { var collision = ps.collision; collision.collidesWith = layerToggle ? (1 << layer0) : (1 << layer1); }

void OnGUI() { layerToggle = GUI.Toggle(new Rect(25, 40, 100, 30), layerToggle, "Toggle Layer"); } }

Did you find this page useful? Please give it a rating: