解説動画
つづき:https://qiita.com/simanezumi1989/private/d6c6d9358dd5d096f03f
画像や素材
ソースコード
PlayerShip.cs
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
// PlayerShipを方向キーで動かす
// ・方向キーの入力を受け取る
// ・Playerの位置を変更する
// 弾をうつ
// ・弾を作る
// ・弾の動きを作る
// ・発射ポイントを作る
// ・ボタンを押したときにたまを生成する:Instantiate
// -------------//
public class PlayerShip : MonoBehaviour
{
public Transform firePoint; // 弾を発射する位置
public GameObject bulletPrefab;
// 約0.02秒に一回実行される
void Update()
{
Shot();
Move();
}
void Shot()
{
if (Input.GetKeyDown(KeyCode.Space))
{
Instantiate(bulletPrefab, firePoint.position, transform.rotation);
}
}
void Move()
{
float x = Input.GetAxis("Horizontal");
float y = Input.GetAxis("Vertical");
transform.position += new Vector3(x, y, 0) * Time.deltaTime * 4f;
}
}
Bullet.cs
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Bullet : MonoBehaviour
{
// 上に動く
void Update()
{
transform.position += new Vector3(0, 3f, 0)*Time.deltaTime;
}
}
スタジオしまづからのお知らせ
スタジオしまづ は「プログラミング未経験でもゲームをリリース」をコンセプトに集まるオンラインサロンを運営しています。
https://camp-fire.jp/projects/view/149191
対象は以下の方としています。興味のある方はぜひ!
・独学でゲームを作れるか心配な方
・コミケで出展側として参加したい方
・一度でいいから自分のゲームを世に出したい方
・ゲームを作って憧れのゲーム会社に就職したい方