おもちゃラボさんのサイトで勉強中〜移動編〜
はてなブログで、プログラミングコードをはてな記法ではりつけるときは、>|言語名|<(記号は全部半角です。)
ここの上の部分は、コピペして使ってください。
今回もおもちゃラボさんのサイトを参考に勉強中です。
nn-hokuson.hatenablog.com
using System.Collections; using System.Collections.Generic; using UnityEngine; public class RocketController : MonoBehaviour { //ゲームオブジェクトのbulletPrefabの変数宣言 public GameObject bulletPrefab; // Start is called before the first frame update void Start() { } // Update is called once per frame void Update() { //左矢印キーを押すと、左へ行く if(Input.GetKey(KeyCode.LeftArrow)) { transform.Translate(-0.1f, 0, 0); }//右矢印キーを押すと、右へ行く else if(Input.GetKey(KeyCode.RightArrow)){ transform.Translate(0.1f, 0, 0); } //スペースを押すと、プレハブが生成されて、自分自身の角度で生成されていく else if (Input.GetKeyDown(KeyCode.Space)){ Instantiate(bulletPrefab, transform.position, Quaternion.identity); } } }