Sceneの遷移について
チェック項目
・Scryptの一番上に、
using UnityEngine.SceneManagement; を記述
・BuildSettingで、各シーンを登録
・遷移先でもBuildSettingの各シーンを登録 /*忘れずに*/
・条件を入力し、メインの文である
SceneManager.LoadScene ("Mainchan");
を記述!
エラー一覧
●error CS1519: Unexpected symbol `<internal>’ in class, struct, or interface member declaration
(原因)コード中に全角空白が含まれてる可能性。
カメラからレイを飛ばす、アニメーター、音関連
カメラからレイを飛ばす
ray= Camera.main.ScreenPointToRay(Input.mousePosition);
- Camera.main メインカメラの取得
マウスのポインターからレイを飛ばす
if(Physics.Raycast(ray,out hit,100)){
★よくわからないけどテンプレらしい
アニメーターの値を設定する
function SetBool(名前: string, value: bool): void;
例:animator.SetBool("Touch",false);
/*SetFloatとSetbool がある。データの”型”を示す。*/
音関連
AudioSource 作って音楽を再生する
手順:
①GameObjectにサウンドファイルをドラック&ドロップ
②audio Sourceを作る
③スクリプトで再生の処理、AudioClipでサウンドの切り替え
よく出る文章
- private AudioSource 特定の名前;/*音源の箱を作る*/
- Audiosource = GetComponent<AudioSource>/*音源AudioSoueceを取得*/
- Audiosource.clip = voice_02; /*特定のサウンド(ここだとボイス2にきりかえ*/
- Audiosource.play(); /*音の再生*/
transform1,敵に追随される(NavMeshSetFloat)
Random.Range(-range,range)
最小値と最大値を設定してランダムな値を取得
transform.forward
ローカル座標のZ軸。transform.forward = Vector3.right; すれば右を向く
.Slerp(from,to,t)
()内部に記載した2点の間で、円を描く
.Angle()
()内部に記載した点の間の角度
Vector3 forward
= Vector3.Slerp( transform.forward, direction, rotationSpeed * Time.deltaTime / Vector3.Angle(transform.forward,direction)
);
transform.LookAt(transform.position + forward);
対象のTransformオブジェクトを設定し、その方向を向かせる
gameObject.FindGameObjectsWithTag ("Dot").length == 0
タグに該当するゲームオブジェクトをすべて取得し、
「もしこれが0個だったら〜(無くなっていたら)」、という処理をしている
敵がメインキャラに追随するときの書き方------
public GameObject target;/*これはあとで「メインキャラ」をドラッグアンドドロップで持ってくる*/
NavMeshAgent agent;
(中略)
agent.destination = target.transform.position;
/*テンプレ的な表現。NavMeshAgentの、destinationに、位置を設定すれば、
自動的にその位置へ移動する。ここでの位置とは、target(メインキャラ)の移動具合*/
animator.SetFloat ("Speed", agent.velocity.magnitude);
/*NavMeshAgentの移動量が、velocity.sqr Magnitudeから取得できる*/
Unityメモ
◯◯.enabled
「有効か無効か」の意。
.enabled=falseで無効になる。.enabledのみで「可能になる」の意ではない
float型 とは
・値の範囲と、精度の違い1。何ビットとか処理とか、いわゆる理系的なやつ。プログラミングの書き方ではfloat型で十分らしい
使用例: var rotationSpeed : float = 100.0;
インスタンスの生成
基本
Instantiate(projectile, transform.Transform~~, transform.rotation) as GameObject;
→「 Instantiate +(進む、回転)」
例:transform.Translate (0, 0, translation);Z方向(手前)に動き、
transform.Rotate (0, rotation, 0);y軸方面に回転
当たり判定(基本)「当たられる側」に書く
function OnCollisionEnter(collision : Collision)
{
if (collision.gameObject.name == "bullet(Clone)"){ ボールが壁に当たったら
デストロイとかの処理(gameObject);壁が消える
}
}
public var◯◯の理解の仕方
「score」は 32ビット整数 -2147483648~2147483647 で表示するの意
「text」 は テキストで表示だよ の意
「power」は 32ビット単精度浮動小数点数 で表示する の意
「target」 は GameObjectが出てくるよ の意