前提・実現したいこと
キャラクターの斬撃に合わせて、パーティクルを発動するスクリプトを作成しましたが、一通り作成したところで不具合を発見。親オブジェクト(キャラ)を回転させたとき、生成したパーティクルがInspector上で設定した地点とズレてしまい、親オブジェクトをY軸に180°回転させたところ、生成位置が反転してしまいました。
どうか、親オブジェクトの向きが変わっても、Inspector上で設定した地点に生成させる方法をご教授いただけると幸いでございます。何卒よろしくお願い致します (≧人≦○)
該当のソースコード
C#
1/*------------------------------------------------------------- 2//BraveのInAttackにて、剣の起動に合わせて斬撃エフェクトを生成 3-------------------------------------------------------------*/ 4using System.Collections; 5using System.Collections.Generic; 6using UnityEngine; 7 8public class BraveSlash : MonoBehaviour 9{ 10//◆◆◆ エフェクト生成用 ◆◆◆// 11 //生成するSlashエフェクト 12 [SerializeField] private GameObject LightSlash; 13 private GameObject Slash; //「Slash」をインスタンス格納用に使用 14 private GameObject Slash02; //「Slash02」をインスタンス格納用に使用 15 16 //LightSlash生成のためのTransform設定 17 [SerializeField] private Vector3 LightSlashPosition = new Vector3(0f, 0f, 0f); 18 [SerializeField] private Vector3 LightSlashRotation = new Vector3(0f, 0f, 0f); 19 [SerializeField] private Vector3 LightSlashScale = new Vector3(1.0f, 1.0f, 1.0f); 20 21 //LightSlash02生成のためのTransform設定 22 [SerializeField] private Vector3 LightSlashPosition02 = new Vector3(0f, 0f, 0f); 23 [SerializeField] private Vector3 LightSlashRotation02 = new Vector3(0f, 0f, 0f); 24 [SerializeField] private Vector3 LightSlashScale02 = new Vector3(1.0f, 1.0f, 1.0f); 25 26 public void SlashEffect() //MeleeAttack1撃目 27 { 28 //生成したエフェクトの大きさを設定。 29 LightSlash.transform.localScale = LightSlashScale; 30 31 //エフェクトの生成する位置を設定。 32 Vector3 position = new Vector3(LightSlashPosition.x, LightSlashPosition.y, LightSlashPosition.z); 33 //エフェクトの生成する角度を設定。インスペクター上から設定できるのはX・Z軸のみ。 34 Vector3 rotation = new Vector3(LightSlashRotation.x, this.transform.eulerAngles.y, LightSlashRotation.z); 35 36 //上記の位置と角度でエフェクトを生成。 37 Slash = (GameObject)Instantiate(LightSlash, position, Quaternion.Euler(rotation)); 38 39 //生成したエフェクトのlocalPositionを「LightSlashPosition」に変更する 40 //Slash.transform.localPosition = LightSlashPosition; 41 42 //生成したエフェクトを子オブジェクトにする。 43 Slash.transform.parent = transform; 44 } 45 46 public void SlashEffect02() //MeleeAttack2撃目 47 { 48 //生成したエフェクトの大きさを設定。 49 LightSlash.transform.localScale = LightSlashScale02; 50 51 //生成したエフェクトのlocalPositionを「LightSlashPosition02」に変更する 52 LightSlash.transform.localPosition = LightSlashPosition02; 53 54 //エフェクトの生成する位置を設定。インスペクター上からの設定が反映させるのはY軸のみ。 55 Vector3 position02 = new Vector3(LightSlashPosition02.x, LightSlashPosition02.y, LightSlashPosition02.z); 56 //エフェクトの生成する角度を設定。インスペクター上から設定できるのはX・Z軸のみ。 57 Vector3 rotation02 = new Vector3(LightSlashRotation02.x, this.transform.eulerAngles.y, LightSlashRotation02.z); 58 59 //上記の位置と角度でエフェクトを生成。 60 Slash02 = (GameObject)Instantiate(LightSlash, position02, Quaternion.Euler(rotation02)); 61 62 //生成したエフェクトのlocalPositionを「LightSlashPosition02」に変更する 63 //Slash02.transform.localPosition = LightSlashPosition02; 64 65 //生成したエフェクトを子オブジェクトにする。 66 Slash02.transform.parent = transform; 67 } 68 69 public void SlashDestroy() //生成したMeleeAttackを削除 70 { 71 //すべての子オブジェクトを削除する 72 foreach (Transform child in gameObject.transform) 73 { Destroy(child.gameObject); } 74 } 75}
詳細
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2019/02/03 08:21