[unity菜鳥]ノート1——関数編

1889 ワード

SendMessage()  
他のオブジェクトのコマンドを呼び出し、スクリプトにカスタム関数を作成してから、SendMessage()コマンドを使用してそのオブジェクトのコマンドを呼び出します.
//① target 



void Renamer(string newName)

{

    gameObject.name=newName;     

}



//② 



GameObject.Find("target").SendMessage("Renamer","target_down");


 
モバイルプラットフォームプログラミングの注意
// , 

GameObject.Find("target").GetComponent<Setter>().Renamer("target_down");

                                  

                                   ↓

GameObject theTarget = GameObject.Find("target");

theTarget.GetComponent<Setter>().Renamer("target_down");


  
Update()とFixedUpdate()
FixedUpdate()は物理エンジンと同期しており、関数が1秒あたり呼び出される回数は固定されています.物理に関連するスクリプトを使用すると、リジッドボディの使用や重力効果など、より適しています.
Update()関数はフレーム数に依存し、呼び出される回数はハードウェア自体のパフォーマンスに依存します.
 
 
 
Input.GetAxis
移動方向を決める.GetAxis(「Horizontal」)はX軸上を移動し、Input.GetAxis(「Vertical」)は、z軸上での移動を表します.
 
UnityでのMoveとSimpleMoveの違い(リファレンス)
以下にまとめる.
Move:重力の影響を受けず、colliderに阻まれます.Move(new Vector(0,0,1)---z軸に1単位移動
SimpleMove:重力の影響を受け、colliderによってブロックされ、SimpleMove(new Vector(0,0,1));----Z軸に移動するTime.デルタタイム*1単位の距離.
 
Quaternion.LookRotation
 
InvokeRepeating
void Start()

{

      //0 ,1 repeat() 

      InvokeRepeating("repeat",0,1);  

}    



void repeat()

{

      Debug.log(" I am repeating every second");      

}


 
Instantiateインスタンス(リファレンス)
static function Instantiate (original : Object, position : Vector3, rotation : Quaternion) : Object
説明:オリジナルオブジェクトをクローンし、クローンオブジェクトに戻ります.