Q&A
実現したいこと
これを付けたオブジェクトをプレイヤーの位置にワープさせ、前進させたい
前提
Unityでシューティングゲームを作っています
球をspaceが押されたときにプレイヤーにワープさせてY+の方向に飛ばしたいです
playerPositionにはプレーヤーのオブジェクトをアタッチしています
while文の中とそのあとの一行は書いてる途中です
発生している問題・エラーメッセージ
Assets\Shot.cs(23,34): error CS0029: Cannot implicitly convert type 'UnityEngine.Transform' to 'UnityEngine.Vector3'
該当のソースコード
C#
1using System.Collections; 2using System.Collections.Generic; 3using UnityEngine; 4 5public class Shot : MonoBehaviour 6{ 7 private Rigidbody2D myRigidBody; 8 public GameObject playerPosition; 9 private float posi = 0; 10 public float shotSpeed = 10; 11 // Start is called before the first frame update 12 void Start() 13 { 14 myRigidBody = this.gameObject.GetComponent<Rigidbody2D>(); 15 } 16 17 // Update is called once per frame 18void FixedUpdate() 19 { 20 Vector2 force = Vector2.zero; 21 if(Input.GetKey(KeyCode.Space)) 22 { 23 transform.position = playerPosition.transform; 24 while(posi <= 5) 25 { 26 force = new Vector2(0,shotSpeed * 1); 27 posi = posi + 1; 28 } 29 posi = 0; 30 } 31 myRigidBody.MovePosition(myRigidBody.position + force * Time.fixedDeltaTime); 32 33 } 34} 35
回答1件
あなたの回答
tips
プレビュー
下記のような回答は推奨されていません。
このような回答には修正を依頼しましょう。
2023/02/12 08:40