チュートリアル「サバイバルシューター」

Unityチュートリアルをやってみました。

Unity is the ultimate game development platform. Use Unity to build high-quality 3D and 2D games, deploy them across mobile, desktop, VR/AR, consoles or the Web, and connect with loyal and enthusiastic players and customers.

 

今回は少し長めですね。

空プロジェクトを作成し、AssetStoreからダウンロード・インポートした状態で動画を進める感じです。

プレイヤーの動かし方、AnimationControllerの使い方、NavigationMeshの使い方を学べますが…
いかんせん英語がわからないwwww ^^;

 

最初、Navigation が機能しなかったが、ふとConsoleを見るとたくさんのエラーが…

“SetDestination” can only be called on an active agent that has been placed on a NavMesh.

なんだこれは…とググったら、[Bake] というものを実行していなかっただけでした。

 

プレイヤーをマウスがある座標の方向を向かせるために回転させたり、プレイヤーをUpdateで移動させる方法が勉強になりました。

今まで我流すぎて、この Vector3.Lerp、Color.Lerp が新鮮…www

 

以下のカメラをプレイヤーに追従させる CameraFollow の場合は、Vector3.Lerp の引数の数値が毎回変化するので、まだなんとなくわかる気もするのですが…

public class CameraFollow : MonoBehaviour {

	[SerializeField]
	private Transform target;

	/** 省略 ... **/

	void FixedUpdate() {
		var targetCamPos = this.target.position + this.offset;
		this.transform.position = Vector3.Lerp (this.transform.position, targetCamPos, this.smoothing * Time.deltaTime);
	}
}

 

ダメージを受けた時に画面を一瞬赤くして透明に戻す以下の処理については、Color.Lerp の引数は変化しないのに… damageImage.color は徐々に透明になっていく…。 なんで?w ^^;

public class PlayerHealth : MonoBehaviour {
	/** 省略 ... **/
	[SerializeField] private Color flashColour = new Color(1f, 0f, 0f, 0.1f);

	/** 省略 ... **/

	void Update () {
		if(damaged) {
			damageImage.color = flashColour;
		} else {
			//Color.Lerp ... 徐々に色を変化させる
			damageImage.color = Color.Lerp (damageImage.color, Color.clear, flashSpeed * Time.deltaTime);
		}
		damaged = false;
	}

	/** 省略 ... **/
}

 

…いまいち飲み込めてないけど、わかるまでなんども練習かな… ^^;;;
ググったら Mathf.Lerp ってwww いやぁ…すごいなーwww ^^;;

Lerpとは 線形補間という意味です。 線形補間 - Wikipedia 今回はUnityで使うメモです。 Unityでは、Color, Material, Mathf, Vector, QuaternionでLerpが使えます。 とりあえず全部使ってみます。 Color まずはColorで使います。 今回はSpriteの色を変えていきます...

 

リソースは用意してある状態で、ヒエラルキーにどんどん追加してインスペクタで設定していく感じのチュートリアルでしたが、色々と知らなかったことが体験できていい内容でした。

PlayerMovement クラスの プレイヤーの移動のさせ方と回転のさせ方も勉強になりました。
ゼロから実装しようとしたら…このコードを思い浮かばないかもしれないけど、その時はこのコードを参照しようwww ^^;

Navigationはもっとチュートリアルで体感しないとわからないな…日本語の動画があるといいな… ^^;;


Add a Comment

メールアドレスが公開されることはありません。 * が付いている欄は必須項目です