前提
複数枚の扉があり、正解の扉の前でスペースキーを押すと、指定の扉に瞬間移動できるゲームを作成しています
実現したいこと
正解の扉の前でスペースキーを押すと、指定の扉に移動
発生している問題・エラーメッセージ
スペースキーを長押ししながら扉に触れに入らないと、瞬間移動が出来ないようになっています。
扉の前でクリックするだけで、瞬間移動させられるようにしたいです。
該当のソースコード
c#
1using System.Collections; 2using System.Collections.Generic; 3using UnityEngine; 4 5public class PlayerController2 : MonoBehaviour 6{ 7 Rigidbody2D rbody2D; 8 float axisH = 0.0f; 9 10 11 public GameObject object1; 12 13 // Start is called before the first frame update 14 void Start() 15 { 16 rbody2D = GetComponent<Rigidbody2D>(); 17 18 } 19 20 // Update is called once per frame 21 void Update() 22 { 23 axisH = Input.GetAxisRaw("Horizontal"); 24 25 } 26 27 void FixedUpdate() 28 { 29 rbody2D.velocity = new Vector2(axisH * 3.0f, rbody2D.velocity.y); 30 } 31 32 void OnTriggerEnter2D(Collider2D collision) 33 { 34 if (collision.gameObject.tag == "door"&& Input.GetKey(KeyCode.Space)) 35 { 36 37 38 transform.position = object1.transform.position; 39 40 41 } 42 43 } 44} 45
試したこと
ここに問題に対して試したことを記載してください。
補足情報(FW/ツールのバージョンなど)
ここにより詳細な情報を記載してください。
回答1件
あなたの回答
tips
プレビュー