0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

FarmRPG Unity PlayerBasics Part1 プレイヤープレハブを作成 SortingGroupsを使ってSpriteの描画順を制御

Last updated at Posted at 2023-05-26

概要

今回はプレイヤーのプレハブを作成します。プレイヤープレハブの子コンポーネントには髪腕、体といった部位のオブジェクトがあります。これらの子オブジェクトのレイヤーを設定して描画順を制御します。

以下実装後の様子です。

gfgfsdgfdsfgsg.gif

開発環境

IDE:Rider
Unity:2020.3.42(LTS)
OS:Windows10

UnityEditor上の設定

ソートレイヤーを作成

下図のようにソートレイヤーを追加します。尚今回はInsntacesレイヤーを使います。

image.png

Playerオブジェクトを作成

サンプルプロジェクトのオブジェクトを参考にしてPlayerオブジェクトを作ります。

SortingGroupコンポーネントの挙動を検証する

別のSpriteRendererアタッチ済みゲームオブジェクトを重ねて、SortingGroupの動きを確認します。尚レイヤーは同じとします。
木のインスペクター
image.png

結果

image.png

ケース 木のレイヤー順序 プレイヤーのSortingGroup プレイヤーのレイヤー順序 結果
A 0 ON 0 木が描画される
B 0 OFF - プレイヤーの全部位が描画される
C 0 ON 1 プレイヤーの全部位が描画される
D 2 OFF - プレイヤーの一部(腕のみ)が描画される胴体部分髪は表示されない。原因は木のレイヤーの順序以下のため

以上の結果からSortingGroupを使うとレイヤーの管理が楽になります。

参考

C#

Unity Editor コンポーネント

Sorting Layer

image.png

Sorting Group

Sprite Renderer

image.png

Unity スクリプト

その他

Section1

github コミット分(個人確認用 privateなので見れません)

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?