블로그 이미지
Every unexpected event is a path to learning for you.

카테고리

분류 전체보기 (2318)N
Unity3D (567)N
Programming (471)
Unreal (4)
Gamebryo (56)
Tip & Tech (183)
협업 (34)
3DS Max (3)
Game (12)
Utility (116)
Etc (92)
Link (31)
Portfolio (19)
Subject (90)
iOS,OSX (38)
Android (13)
Linux (5)
잉여 프로젝트 (2)
게임이야기 (1)
Memories (19)
Interest (37)
Thinking (36)
한글 (26)
PaperCraft (5)
Animation (408)
Wallpaper (2)
재테크 (19)
Exercise (3)
나만의 맛집 (2)
냥이 (9)
육아 (7)
Total1,339,009
Today22
Yesterday214
Statistics Graph

달력

« » 2019.11
          1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30

공지사항

태그목록

Why doesn’t my particle system show in front of my sprites??

Particle System Sort LayerThis one had me befuddled for a little while. I could not figure out why my particle system was not showing up in front of my sprites for the life of me. I had the “Layer” set properly but I couldnot find a place to set the “Sorting Layer”. I came across some other folks who were saying you had to set the sorting layer manually in code so theparticle system would show up where it needed to (sorry, I can’t remember the references!). Okay, that seems easy enough, let’s see if we can figure that out. It looks like we can do that via the following code. The “sortingLayerName” is just a string of a sorting layer you have defined in Unity and the “sortingOrder” is an integer that specifies the z-order in that sorting layer. The higher the number, the closer the object “looks” to you.


1
2
particleSystem.renderer.sortingLayerName = sortingLayerName;
particleSystem.renderer.sortingOrder = sortingOrder;

So now let’s just make this into a script so we can easily apply it to all particle systems we create.

I put the following code into a file named “ParticleSystemFix.cs” and attached it to any particle systems I create.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
using UnityEngine;
using System.Collections;
 
public class ParticleSystemFix : MonoBehaviour {
 
public string sortingLayerName;
public int sortingOrder;
 
/**
 */
void Start() {
    particleSystem.renderer.sortingLayerName = sortingLayerName;
    particleSystem.renderer.sortingOrder = sortingOrder;
    enabled = false;
  }
}

I’ll usually tell a script to disable itself once it is done initializing or if the code in the Update() function starts to be skipped because of a certain condition. I’m sure there has to be a slight performance advantage to doing this…every little bit helps.  Plus it lets me know if something is executing properly when I expect the script to become disabled.

Particle System Sort LayerNow, just attach this script to any particle system; there in the inspector, you can define a “sortingLayerName” and “sortingOrder” on the “ParticleSystemFix”.  I used a large number like 999 as my “sortingOrder” since I want my particle systems to appear on top of all my sprites.

 

 

Particle System Sort LayerMake sure that what you pass into the “sortingLayerName” is defined in Unity!

That is about it, as long as the “sortingLayerName” for your particle system is where it needs to be hierarchically, your particle system should appear on top of the sprites.

 

 

 

 


출처 : 

Posted by blueasa

댓글을 달아 주세요

  1. 2015.07.21 19:19 아림이  댓글주소  수정/삭제  댓글쓰기

    저... 초대장을 주실 수 없으실까 해서요..

    블로그는 http://blog.naver.com/wh4993 구요.
    이메일은 wh4993@naver.com 입니다.

    티스토리에서 글을 자주 읽는데 매번 읽고 공감만 하고 가기가 죄송하더라고요. 그래서 가입한 후 댓글과 공감을 나누고 싶어서 이렇게 초대장을 받고자 합니다. 꾸벅

    • 2015.07.21 19:37 신고 blueasa  댓글주소  수정/삭제

      안녕하세요~
      막 사진올리고 있는 사이 리플을 달아주셨네요~
      초대장은 보내드렸습니다.
      확인해보시고 좋은 하루 되세요~ :)