本日外部ストレージを入手しましたが、Unity,xcode,ZBrushcore,さらにblenderを入れるとなるとアプリと最低限の設備だけでmacbookの120GB程度のストレージはパンパンになりそうです。
常時外部ストレージと接続して作業することを考えるとデスクトップ型の方が良いのかもしれません。
ちなみに、メモリとストレージの定義を再確認しました。
//tips
//terrainの機能の補足
Terrainの使い方で他のサイトを調べていた際に、現在の使い方が旧バージョンのUnityと大きく変わっているようなので、再度有用な機能を記載する。
2019年以降のUnityではterrainの地形の選択は、インスペクターの中の筆のマークを選択し、paint textureの中にあるEdit Terrain Layersで作成、追加することができる。
初期時点では何も入っていないため、asset storeで素材をダウンロードする必要がある。
Terrain layersの下に記載されるDiffuse、Normal map、Mask mapはマップ種類の違いにより使い分けられ、基本はDiffuseの仕様となる。
Diffuse テクスチャは、Terrain レイヤーの基本のカラーテクスチャ/カラーチャンネルを表す。
https://docs.unity3d.com/ja/2018.4/Manual/class-TerrainLayer.html
https://docs.unity3d.com/ja/2018.4/Manual/StandardShaderMaterialParameterNormalMap.html
また、筆のマークの左側にあるcreate neighbor terrainsを押すと、現在製作しているterrain周辺をクリックする枠が発生し、クリックするだけで周囲にterrainを生成することができる。
周りのterrainと使用しているterrainの色が異なる場合は、歯車マークterrain settingの中のmaterialが異なっている場合があるので設定を見直す。
//destroyでプレイヤーがいなくなる可能性があるときの座標の取得の管理
destroyでプレイヤーを消滅させることがある場合、下記のようなプレイヤーの座標の取得はエラーになってしまう可能性が高いので、
Vector3 p2 = this.Player.transform.position;
その場合は事前にif (Player != null)の中にVector3 p2 = this.Player.transform.position;を入れてしまうことで削除後にエラーが起こらなくすることができる。
void Update ()
{
if (Player != null)
{
Vector3 p1 = transform.position;
Vector3 p2 = this.Player.transform.position;
if (p1 == p2)
{
Destroy(Player);
}
}
}
//rotationでenemyの動きを回転させたい場合
Rotationは少し複雑な構造になっており、transform.rotationだけでは使うことができない。
そのため、transform.rotation = Quaternion.Euler(0, 90, 0);のようにQuaternion.Eulerという関数を使うことで、その時点のrotationを設定することができる。
参考サイト:
条件分岐にうまく組み合わせることで動きに連動した顔の向きにすることが可能となる。
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
public class EnemyController3 : MonoBehaviour
{
GameObject Player;
Vector3 MOVEX = new Vector3(1.0f, 0, 0);
Vector3 MOVEY = new Vector3(0, 1.0f, 0);
Vector3 MOVEZ = new Vector3(0, 0, 1.0f);
float step = 3.0f; // 移動速度
Vector3 target; // 入力受付時、移動後の位置を算出して保存
private int count = 0;
void Start()
{
target = transform.position;
this.Player = GameObject.Find("Player");
}
void Update()
{
if (Input.anyKeyDown)
{
count++;
if (count == 1)
{
target = transform.position - MOVEX;
transform.rotation = Quaternion.Euler(0, 270, 0);
}
if (count == 2)
{
target = transform.position - MOVEX;
}
if (count == 3)
{
target = transform.position + MOVEX;
transform.rotation = Quaternion.Euler(0, 90, 0);
}
if (count == 4)
{
target = transform.position + MOVEX;
count = 0;
}
}
Move();
Vector3 p1 = transform.position;
Vector3 p2 = this.Player.transform.position;
if (p1 == p2)
{
if (Player != null)
{
Destroy(Player);
Invoke("Over", 0.0f);
}
}
}
void Move()
{
this.transform.position = Vector3.MoveTowards(transform.position, target, step * Time.deltaTime);
}
void Over()
{
SceneManager.LoadScene("GameOver");
}
}
//cameraの切り替えを行う
Maincameraとは別にsubcameraを追加した場合、通常subcameraの視点がビューに表示されてしまう。
その要因はcamera内にあるdepthの違いにあり、maincameraは通常-1、subcameraは0に設定されているため、このようなことが起こる。
depthの値が大きい方を優先して反映するので、シーン内の複数カメラの描写順番を管理することに使用できる。
スクリプトによるカメラの切り替えを実装する。
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class CameraControll : MonoBehaviour
{
private GameObject mainCamera; //メインカメラ格納用
private GameObject subCamera; //サブカメラ格納用
//呼び出し時に実行される関数
void Start()
{
//メインカメラとサブカメラをそれぞれ取得
mainCamera = GameObject.Find("MainCamera");
subCamera = GameObject.Find("SubCamera");
//サブカメラを非アクティブにする
subCamera.SetActive(false);
}
//単位時間ごとに実行される関数
void Update()
{
//スペースキーが押されている間、サブカメラをアクティブにする
if (Input.GetKey("space"))
{
//サブカメラをアクティブに設定
mainCamera.SetActive(false);
subCamera.SetActive(true);
}
else
{
//メインカメラをアクティブに設定
subCamera.SetActive(false);
mainCamera.SetActive(true);
}
}
}
//プレイヤーへの移動方向付加後、操作方向はベクトル固定にしたいためmaincameraをPlayerの子要素から外す
プレイヤーに移動した後に移動方向を向くプログラムを組むと子要素にしたcameraも同じように回転してしまい画面と入力キーの方向がマッチしなくなる。
this.transform.LookAt(nextPosition);をプレイヤーの移動後の方向プログラムとして導入した。Cubeをプレイヤーとした場合は少しわかりづらいが。
この問題は、メインカメラをプレイヤーの子要素から外し、プレイヤーの回転要素を受けなくした後、相対位置で追従する下記のスクリプトをメインカメラに付加することで解決した。
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class MainCamera : MonoBehaviour
{
private GameObject player; //プレイヤー情報格納用
private Vector3 offset; //相対距離取得用
// Use this for initialization
void Start()
{
//unitychanの情報を取得
this.player = GameObject.Find("Player");
// MainCamera(自分自身)とplayerとの相対距離を求める
offset = transform.position - player.transform.position;
}
// Update is called once per frame
void Update()
{
//新しいトランスフォームの値を代入する
transform.position = player.transform.position + offset;
}
}
変更したプレイヤースクリプトは下記となる。
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerController5 : MonoBehaviour
{
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
if (Input.GetKeyDown(KeyCode.LeftArrow))
{
Vector3 nextPosition = transform.position;
nextPosition.x = Mathf.Clamp(nextPosition.x - 1, 0, 10.0f);
this.transform.LookAt(nextPosition);
transform.position = nextPosition;
}
if (Input.GetKeyDown(KeyCode.RightArrow))
{
Vector3 nextPosition = transform.position;
nextPosition.x = Mathf.Clamp(nextPosition.x + 1, 0, 9.0f);
this.transform.LookAt(nextPosition);
transform.position = nextPosition;
}
if (Input.GetKeyDown(KeyCode.UpArrow))
{
Vector3 nextPosition = transform.position;
nextPosition.z = Mathf.Clamp(nextPosition.z + 1, 0, 9.0f);
this.transform.LookAt(nextPosition);
transform.position = nextPosition;
}
if (Input.GetKeyDown(KeyCode.DownArrow))
{
Vector3 nextPosition = transform.position;
nextPosition.z = Mathf.Clamp(nextPosition.z - 1, 0, 10.0f);
this.transform.LookAt(nextPosition);
transform.position = nextPosition;
}
}
public void PushLeftButton()
{
Vector3 nextPosition = transform.position;
nextPosition.x = Mathf.Clamp(nextPosition.x - 1, 0, 10.0f);
this.transform.LookAt(nextPosition);
transform.position = nextPosition;
}
public void PushRightButton()
{
Vector3 nextPosition = transform.position;
nextPosition.x = Mathf.Clamp(nextPosition.x + 1, 0, 9.0f);
this.transform.LookAt(nextPosition);
transform.position = nextPosition;
}
public void PushUpButton()
{
Vector3 nextPosition = transform.position;
nextPosition.z = Mathf.Clamp(nextPosition.z + 1, 0, 9.0f);
this.transform.LookAt(nextPosition);
transform.position = nextPosition;
}
public void PushDownButton()
{
Vector3 nextPosition = transform.position;
nextPosition.z = Mathf.Clamp(nextPosition.z - 1, 0, 10.0f);
this.transform.LookAt(nextPosition);
transform.position = nextPosition;
}
}
cameraControllerのスクリプトには変更を加えていない。
//MacBook用ELECOM外付けSSD ESD-EJシリーズの設定
マニュアルにはMacbookの設定が記載されておらずわかりずらかったので、導入方法を記載する。
外付けSSDUSBコネクタをmacの接続口に変換するもので接続。
Finderから移動→ユーティリティ→ディスクユーティリティへ遷移。
外部に表示されるSSDを選択し、消去をクリック、クリックすると名前とフォーマット名が出てくるので、「MacOS拡張(ジャーナリング)」を選択し、消去を押すとmac版へのカスタマイズされ直す。
バックアップは「使用しない」を選択した。
あとはFinderからSSDを開き、移動させたいものをドラッグアンドドロップするだけで良い。