実現したいこと
spaceが押されたらplayerPositionにワープして上方向に飛ばしたい
前提
playerPositionにはプレイヤーの子オブジェクトをアタッチしてあります
該当のソースコード
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 offScreen = 0; 10 // Start is called before the first frame update 11 void Start() 12 { 13 myRigidBody = this.gameObject.GetComponent<Rigidbody2D>(); 14 } 15 16 // Update is called once per frame 17void FixedUpdate() 18 { 19 Vector2 force = Vector2.zero; 20 if(Input.GetKey(KeyCode.Space)) 21 { 22 transform.position = playerPosition.transform.position; 23 force = new Vector2(0,10); 24 offScreen = 0; 25 } 26 myRigidBody.MovePosition(myRigidBody.position + force * Time.fixedDeltaTime); 27 28 } 29private void OnBecameInvisible() 30 { 31 offScreen = 1; 32 } 33}
試したこと
force = new Vector2(0,10);
の()内をどう変えても下方向にしか動きません
>()内をどう変えても下方向にしか動きません
マイナスにしても?

回答2件
あなたの回答
tips
プレビュー