提示コードのコメント部内部のコードですが武器がプレイヤーの周りを周回するという仕様を実装したいのですがプレイヤーどうすれば実装できるのでしょうか? プレイヤーがその場を動かない場合だと実装出来るのですがプレイヤーが動く場合周回する円が広がってしまい上手く実装できません。
cs
1using System.Collections; 2using System.Collections.Generic; 3using UnityEngine; 4using System.Linq; 5 6public partial class Player_Control 7{ 8 9 [SerializeField,Range(3,10)] private float instancePositionDistance; // 10 [SerializeField, Range(3,100)] private int objectPoolInstance; // 11 [SerializeField, Range(0.0f, 3.0f)] private float intervalTime; // 12 [SerializeField] private List<GameObject> weaponList; // 13 14 15 private List<List<GameObject>> instanceWeapon; // 16 private float time; // 17 private int listNumber; // 18 private GameObject weaponInstancePosition; // 19 private Vector3 forward; // 20 private bool isInstance; // 21 private GameObject nowInstance; // 22 private bool isChangeWeapon; //武器切替 23 private List<GameObject> weapon; //武器切替オブジェクト 24 private Vector3 prevPosition; 25 public void Attack_Init() 26 { 27 time = 0; 28 isInstance = true; 29 weapon = new List<GameObject>(); 30 31 32 weaponInstancePosition = transform.Find("WeaponInstancePosition").gameObject; 33 instanceWeapon = new List<List<GameObject>>(); 34 35 foreach (GameObject g in weaponList) 36 { 37 instanceWeapon.Add(new List<GameObject>()); 38 39 for (int i = 0; i< objectPoolInstance; i++) 40 { 41 instanceWeapon.Last().Add(Instantiate(g, weaponInstancePosition.transform.position, weaponInstancePosition.transform.rotation)); 42 instanceWeapon.Last().Last().SetActive(false); 43 44 } 45 } 46 47 48 for (int i = 0; i < weaponList.Count(); i++) 49 { 50 weapon.Add(CreateObject(i, weaponInstancePosition.transform.position, weaponInstancePosition.transform.rotation)); 51 } 52 53 54 55 56 listNumber = 0; 57 58 } 59 60 61 private void Attack() 62 { 63 Vector3 f = forward; 64 f.y = 0.20f; 65 66 weaponInstancePosition.transform.position = transform.position + f * instancePositionDistance; 67 68 if(nowInstance != null) 69 { 70 nowInstance.transform.position = weaponInstancePosition.transform.position; 71 nowInstance.transform.rotation = Quaternion.LookRotation(f) * Quaternion.Euler(90, 0, 0); 72 } 73 74 if (Input.GetMouseButtonDown(0)) 75 { 76 if( (time >= intervalTime) && (isInstance == false)) 77 { 78 nowInstance.transform.rotation = Quaternion.LookRotation(f) * Quaternion.Euler(90, 0, 0); 79 nowInstance.GetComponent<Bullet>().Active(f); 80 isInstance = true; 81 time = 0; 82 } 83 } 84 85 86 } 87 88 private void ViewWeapon() 89 { 90 if(isChangeWeapon == true) 91 { 92 for (int i = 0; i < weaponList.Count(); i++) 93 { 94/////////////////////////////////////////////////////////////////////////////////////////////////////////////// 95 Debug.Log("あああ"); 96 weapon[i].gameObject.SetActive(true); 97 weapon[i].gameObject.transform.position = transform.position - prevPosition; 98 weapon[i].gameObject.GetComponent<Bullet>().ChangeViewMaterial(); 99 100 weapon[i].transform.RotateAround(transform.position, new Vector3(0,1,0),0.5f); 101/////////////////////////////////////////////////////////////////////////////////////////////////////////////// 102 103 } 104 } 105 } 106 107 108 private void SelectWeapon() 109 { 110 if(Input.GetKeyDown(KeyCode.Q)) 111 { 112 if(listNumber > 0 ) 113 { 114 nowInstance.gameObject.SetActive(false); 115 listNumber--; 116 isChangeWeapon = true; 117 nowInstance = CreateObject(listNumber, weaponInstancePosition.transform.position, weaponInstancePosition.transform.rotation); 118 nowInstance.gameObject.GetComponent<Bullet>().SetActiveInstanceEffect(intervalTime); 119 } 120 } 121 else if (Input.GetKeyDown(KeyCode.E)) 122 { 123 if (listNumber < weaponList.Count - 1) 124 { 125 nowInstance.gameObject.SetActive(false); 126 listNumber++; 127 nowInstance = CreateObject(listNumber, weaponInstancePosition.transform.position, weaponInstancePosition.transform.rotation); 128 nowInstance.gameObject.GetComponent<Bullet>().SetActiveInstanceEffect(intervalTime); 129 } 130 } 131 132 if (isInstance == true) 133 { 134 nowInstance = CreateObject(listNumber, weaponInstancePosition.transform.position, weaponInstancePosition.transform.rotation); 135 nowInstance.gameObject.GetComponent<Bullet>().SetActiveInstanceEffect(intervalTime); 136 isInstance = false; 137 } 138 } 139 140 public void Attack_FixedUpdate() 141 { 142 Vector3 f = Vector3.Scale(Camera.main.transform.forward.normalized, new Vector3(1, 0, 1)).normalized; 143 forward = (f + Camera.main.transform.forward).normalized; 144 145 time += Time.deltaTime; 146 } 147 148 GameObject CreateObject(int select,Vector3 pos,Quaternion rot) 149 { 150 foreach(GameObject gg in instanceWeapon[select]) 151 { 152 if( gg.activeSelf == false) 153 { 154 gg.SetActive(true); 155 gg.gameObject.GetComponent<Bullet>().Init(); 156 157 158 gg.transform.position = pos; 159 gg.transform.rotation = rot; 160 161 return gg; 162 } 163 } 164 165 instanceWeapon[select].Add(Instantiate(weaponList[select])); 166 instanceWeapon[select].Last().SetActive(true); 167 instanceWeapon[select].Last().transform.position = pos; 168 instanceWeapon[select].Last().transform.rotation = rot; 169 instanceWeapon.Last().Last().gameObject.GetComponent<Bullet>().Init(); 170 171 return instanceWeapon.Last().Last().gameObject; 172 } 173} 174
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
退会済みユーザー
2021/08/06 01:13
退会済みユーザー
2021/08/06 01:16
2021/08/06 02:54