Unityでパーティクルを、衝突によるオブジェクトのDestroyと同時に生成したいです。
衝突した座標に生成しようと考えています。また、RayCastを当たり判定として使っております。
一応スクリプトも下に載せておきます(Enemyレイヤーに当たったら生成する)。
初心者ですので、より具体的に教えてくださるとありがたいです。
C#
1using System.Collections; 2using System.Collections.Generic; 3using UnityEngine; 4 5public class ShotCursor : MonoBehaviour 6{ 7 8 private AudioSource audioSource; 9 10 // カーソルに使用するテクスチャ 11 [SerializeField] 12 private Texture2D cursor; 13 GameObject director; 14 15 GameObject call; 16 17 18 void Start() 19 { 20 this.call = GameObject.Find("GameDirector"); 21 // カーソルを自前のカーソルに変更 22 this.director = GameObject.Find("GameDirector"); 23 Cursor.SetCursor(cursor, new Vector2(cursor.width / 2, cursor.height / 2), CursorMode.ForceSoftware); 24 audioSource = GetComponent<AudioSource>(); 25 } 26 27 void Update() 28 { 29 // マウスの左クリックで撃つ 30 if (Input.GetButtonDown("Fire1")) 31 { 32 Shot(); 33 34 audioSource.PlayOneShot(audioSource.clip); 35 36 } 37 } 38 39 // 敵を撃つ 40 void Shot() 41 { 42 Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); 43 RaycastHit hit; 44 45 if (Physics.Raycast(ray, out hit, 100f, LayerMask.GetMask("Enemy"))) 46 { 47 48 if (Physics.Raycast(ray, out hit)) { 49 if (hit.collider.tag == "100") { 50 call.GetComponent<GameDirector>().Get100(); 51 Debug.Log("+100"); 52 }else if(hit.collider.tag == "500"){ 53 54 call.GetComponent<GameDirector>().Get500(); 55 56 } 57 else if (hit.collider.tag == "harf") 58 { 59 call.GetComponent<GameDirector>().Getharf(); 60 } 61 else if (hit.collider.tag == "secret") 62 { 63 call.GetComponent<GameDirector>().Getsecret(); 64 } 65 } 66 Destroy(hit.collider.gameObject); 67 } 68 } 69}
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2019/06/17 22:07