皆さんこんにちは!
ユニブレです。
今回は
シューテイングゲーム作成時に
使用している
テクニックを
解説していきます!
本編でも
解説はしていますが、
何度も見ることで
より知識として
落とし込みやすく
なりますので、
こちらにも目を通して
実践してみてください!
環境は
MacOS Catalina:ver 10.15.4
Unity:ver2019.4.3f1
です。
PR
1.キーボード入力の取得方法
まずはキーボードの入力を
受け取る方法を
解説していきます。
- キャラの移動
- 攻撃
などで使うテクニックです。
ひとまずは
CreateEmptyで
オブジェクトを作成してください!
その後にC#Script(名前はtest)を作成しましょう。
testをオブジェクトに
ドラッグ&ドロップしてアタッチしましょう。
作成したScriptに
下記のコードを記述してください!
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Collections; | |
using System.Collections.Generic; | |
using UnityEngine; | |
public class test : MonoBehaviour | |
{ | |
void Update() | |
{ | |
float x = Input.GetAxis("Horizontal"); | |
Debug.Log(x); | |
float y = Input.GetAxis("Vertical"); | |
Debug.Log(y); | |
if(Input.GetKeyDown(KeyCode.Space)) | |
{ | |
Debug.Log("spaceが押されたよ!"); | |
} | |
} | |
} |
これでキーボードと
Spaceの入力を
受け取ることが
できているはずです!
2.TextObjectの取得と変更
ここではUIの
表示変更の時に
よく使う
- Text取得方法
- Text変更方法
について解説していきます。
まずはUIからTextを作成しましょう。
見えやすいように
下記のように設定を変更しておいてください!
その後UIManagerの
- Script
- Object
を作成してください。
スクリプトには下記コードを記述してください!
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Collections; | |
using System.Collections.Generic; | |
using UnityEngine; | |
using UnityEngine.UI; | |
public class UIManager : MonoBehaviour | |
{ | |
public Text text; | |
void Start() | |
{ | |
text.text = "Hello"; | |
} | |
} |
記述が完了したら、
UIManagerにTextをドラッグ&ドロップしてください!
これでPlayボタンを押せば、
表示がHelloに変わります!