スクリプトを当てはめた時のエラー

スクリプトを当てはめた時のエラー

〜〜because the script class cannot be found. Make sure that there are no compile errors and that the file name and class name match.

スクリプトの「ファイル名」と、

スクリプト内の一行目(public class〜〜〜)」 が同じかどうか確認!

 

 

カメラからレイを飛ばす、アニメーター、音関連

カメラからレイを飛ばす

 rayCamera.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◯◯の理解の仕方

f:id:jyunokko:20160505185336p:plain

「score」 32ビット整数 -2147483648~2147483647 で表示するの意

「text」  テキストで表示だよ の意

 

f:id:jyunokko:20160505185642p:plain

「power」は 32ビット単精度浮動小数点数 で表示する の意

「target」  GameObjectが出てくるよ の意