スペースシューター
Space Shooter
「Space Shooter」公式チュートリアル
【事前学習】前回学んだ機能を再確認しておきましょう。
Unityのチュートリアル「Space Shooter」では、アセットの素材を使ってプロジェクトを作成していく手順を学びます。Unityの多彩な機能を身につけて行ってください。
チュートリアルの進め方
公式ページにはチュートリアルがYouTubeの動画で示されています。本チュートリアルは残念ながら日本語の字幕もありませんが、英単語はUnityで用いられているものや比較的簡単なものですので英語の字幕を参考にして頑張ってください。YouTubeの設定(歯車のアイコン)をクリックして字幕を英語にしてください。また、余力のある方はYouTubeは再生速度を変更できますので、少し速度を落として英語のリスニング能力を養うのも良いでしょう。
Introduction to Space Shooter
最初の動画で本プロジェクトの一連の流れを把握します。
Game Setup, Player and Camera
Setting up the project
(注意事項)
- (テンプレートは3Dで)新しく「Space Shooter」という名前のプロジェクトを生成。シーンは新しく保存せずにSampleSceneを利用します。このビデオまではビデオを閲覧するだけで、以下の操作以外は不要です。
- Asset Storeにつないで、「Space Shooter」で検索して、Space Shooter Tutorialをダウンロード、インポートします。素材
- LayoutはTallがお勧めです。
- Unity の WebPlayerは廃止されており、代替はWebGLが担っていますが、ここではFile/Build Settingsの変更はせずに、通常のPC Standaloneアプリとして開発しましょう。
- Edit/Project Settings/Player/Resolution and PresentationでDefault Is Native Resolutionのチェックを外すと画面解像度を設定できます。幅600pixel、高さ900pixelで生成します。後で Gameタブの直下のDisplay1の右の項目をStandalone(600x900)に変更してください。
Game Setup, Player and Camera
The player GameObject
(注意事項)
- Alt+左ボタンドラッグで視点をピボットポイントを中心に回転します。
- Mesh Collider を追加して Convex,Is Trigger にチェック。
Game Setup, Player and Camera
Camera and lighting
(注意事項)
- Main CameraのPosition(0,10,5)、Rotation(90,0,0)、ProjectionをOrthographic、そのSizeを10に設定します。
- 環境光の設定は Window/Rendering/Lighting/Environment で Source の Skybox を Color に変更、Ambient Color を Black(0,0,0) に変更
- Main Light(Directional Light) のRotation(20,-115,0) Intensity0.75 色はWhite(255,255,255)
- Fill Light(Directional Light) のRotation(5,125,0) Intensity0.5 色は水色(128,192,192)
- Rim Light(Directional Light) のRotation(-15,65,0) Intensity0.25 色はWhite(255,255,255)
Game Setup, Player and Camera
Adding a background
(注意事項)
- Hierarcy/Create/Quadで背景(BackGround)を生成、Position(0,-10,0)、Rotation(90,0,0)、Scale(15,30,1)。Mesh Collider を削除。
- 背景のテクスチャをBackGroundオブジェクトにドラッグ&ドロップなどで適用する。
- BackGround の Inspectorにあるテクスチャのコンポーネントの Shader の項目を Standard から Universal Render Pipeline/Unlit に変更
Game Setup, Player and Camera
Moving the player
- Playerの子に Assets/Prefabs/VFX/Engines/engines_player.prefab を追加
- PlayerにアタッチするPlayerController.csスクリプトを以下のように改変。
using UnityEngine;
using UnityEngine.InputSystem;
public class PlayerController : MonoBehaviour
{
public InputAction move;
public float speed = 0.3f;
public float tilt = 30.0f;
Rigidbody rb;
Vector3 movement;
void Start(){
rb = GetComponent();
}
void OnMove(InputAction.CallbackContext c){
var movement2D= c.ReadValue();
movement=new Vector3(movement2D.x, 0f, movement2D.y);
}
void FixedUpdate(){
if(move.IsPressed()){
rb.position += movement * speed;
rb.position = new Vector3(
Mathf.Clamp(rb.position.x, -6, 6),
0.0f,
Mathf.Clamp(rb.position.z, -4, 8)
);
rb.rotation = Quaternion.Euler(0.0f, 0.0f, movement.x * -tilt);
}else{
rb.rotation = Quaternion.identity;
}
}
void Awake(){
move.performed+=OnMove;
}
void OnEnable(){
move.Enable();
}
}
【事後学習】本日学んだ機能を再確認しておきましょう。
This site is powered by