0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Unity:2DShootingの作り方 #1

Last updated at Posted at 2020-04-20

解説動画

つづき: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
対象は以下の方としています。興味のある方はぜひ!
・独学でゲームを作れるか心配な方
・コミケで出展側として参加したい方
・一度でいいから自分のゲームを世に出したい方
・ゲームを作って憧れのゲーム会社に就職したい方

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?