unity

make a block wall with code コードで多数のブロックから成る壁を生成

function Start () { for (var y = 0; y < 5; y++) { for (var x = 0; x < 5; x++) { var cube = GameObject.CreatePrimitive(PrimitiveType.Cube); cube.AddComponent(Rigidbody); cube.transform.position = Vector3 (x, y, 0); } } } //add it to GameObj…

mouse touch object マウスでオブジェクトに触れたことを検知

function OnMouseEnter () { renderer.material.color = Color.red; } //attach this script to cube or so.

子供を全部移動

// Moves all transform children 10 units upwards! for (var child : Transform in transform) { child.Translate(0, 10, 0); } //他オブジェクトとのやり取り //http://unity3d.com/support/documentation/ScriptReference/index.Accessing_Other_Game_Ob…

タグ追加

Tagsを展開してElementに書く。

occlusion culling static オクルージョンカリング

ビルなど、動かないものはStaticにチェックしておくと オクルージョンカリングによりパフォーマンスが上がるhttp://unity3d.com/support/documentation/Components/class-GameObject.html

オブジェクト同士のやり取り

GetComponent / SendMessage

animation layer アニメーション レイヤー化

//数字が大きい方が動いているときは、そちらが優先して再生される。 function Start () { animation[“idle”].layer = -2; animation["attack01"].layer = 1; }

他のオブジェクト / 別のスクリプト の関数を呼ぶ / 関数呼び出し : GameObject.SendMessage

http://unity3d.com/support/documentation/ScriptReference/GameObject.SendMessage.html // Calls the function ApplyDamage with a value of 5 gameObject.SendMessage ("ApplyDamage", 5.0); // Every script attached to the game object // that has a…

unitypackage export 出力

アセット(プレハブやシーン)を右クリック>export package マテリアルでテクスチャを貼ったのなども反映されるので Unityコミュニティの人たちで共有するには良い形式

SS screen capture スクリーンショット

Application.CaptureScreenshot()

オブジェクトをマウスでクリック

Camera.main.ScreenPointToRay(Input.mousePosition);

scene シーン 順番 最初のシーン

file > build settings リスト内にプロジェクトタブからシーンファイルをドラッグアンドドロップ

blenderで作ったアニメーションの武器部分に unityからヒット領域を加える

武器(名前はCylinder)の子にヒット用オブジェクトを加えればOK.Blenderの方で透明な領域を加えておいてもいいけれど、 Unityから追加したほうが試行錯誤できそう。

ピンポン再生

split animation設定時などでループ再生やピンポン再生をしていできる。 ピンポン再生とは、順再生、逆再生と行うことである。

複数アニメーション split animation

Blenderで 右パンチ、左パンチ、右キック、左キック のアニメーションを各60フレームで作り、 それらのアニメーションが連続して入ったFBXファイルを Unityにインポート。 Unity側で Inspector > FXXImporter > Split Animationsから フレームの範囲と名前を…

animation loop

blenderでアニメーションを付けてunityへ。 unityでゲームを実行するとアニメーションが自動実行される。 (動かないようにもunity側で管理できる) しかしループされなかったのでAnimation Wrap ModeをLoopにしたらループした。 これで敵の待機モーションなど…

animation rig

blenderでrig, animation, fbx export -> unity3dで再生まで完了。 TODO : アニメーションループ TODO : もう1度復習 TODO : モデルをちゃんと作る TODO : テクスチャも TODO : NormalMapも

キーボード入力

Input.GetKeyDown http://unity3d.com/support/documentation/ScriptReference/Input.GetKeyDown.html KeyCode http://unity3d.com/support/documentation/ScriptReference/KeyCode.html

衝突した相手オブジェクトにダメージを与える

http://blog.livedoor.jp/akinow/archives/52183427.html 衝突した相手オブジェクトにダメージを与える OnTriggerEnter()文中でHitしたオブジェクトのCollider情報が検出できるわけです。 var damage:int=100; function OnTriggerEnter( otherObject: Collid…

mqo blender importer インポート

http://d.hatena.ne.jp/ousttrue/searchdiary?word=%2A%5BBlender%5D からの http://sourceforge.jp/projects/meshio/wiki/FrontPage で meshio-blender25 (pymeshio-1.8.6.zip) をDLして配置。 Readmeを見てチェックを入れたらImportできた。 テクスチャの…

unity3d movie mp4 ムービー

Movie Playback is only possible with Unity Pro.だってさー! ;_;

orthographic view camera 'final fantasy tactics', 'tactics ogre', シミュレーションゲーム 平行投影

平行投影のゲームも作れる! 右上のギズモをShift+クリックでIso Viewになる。 タクティクスオウガのように、遠いキャラも同じ大きさに見えるようになる。 ゲームのProjectionをそのようにしたければ、 カメラのProjectionをOrthographicにすればよい。

AI プレイヤーが近い時だけ敵AIを動かす

赤い球に入った敵AIだけを有効にする工夫。 カメラに見えないオブジェクトをunableにするOnBecameVisibleもあるけれど、 http://www.cis.sojo-u.ac.jp/~izumi/Unity_Documentation_jp/Documentation/ScriptReference/index.Performance_Optimization.html 背…

別のスクリプトにアクセス

//from ScriptB scriptA = GetComponent("ScriptA");

別のオブジェクト 他のオブジェクト 探す Find

■子や親を探す 子や親のオブジェクトをゲームオブジェクトのTransformコンポーネントから探せる // Find the child "Hand" ofthe game object // we attached the script to transform.Find("Hand").Translate(0,1, 0); ■関数 transformを階層から発見したら…

関数の追加

function Update () { otherScript = GetComponent(OtherScript); otherScript.DoSomething(); } 次のスクリプトとOtherScriptを、同じゲームオブジェクトに付加してくださいこうやって必要な関数だけをオブジェクトに追加していける! http://www.cis.sojo-…

【ゲーム開発】小さい入力の時はあまり動かないようにするための工夫

レースゲームとかに使えるね! 昔のアーケードレースゲームの時点で、 ハンドルを少しだけ切ったら微妙に動いて、 ハンドルを大きく切ったら大きく動く工夫がされていました。 入力と、物体を動かす力が線形ではなく、二次関数の方がよい。 ヒント:方向ベク…

BeamBox raycast line renderer ビーム 光線 他のオブジェクト 関数呼び出し

回転する箱からビームが出ていて、Player(YOU)がジャンプでよけるゲーム。 ビームに当たるとYOUは血(パーティクル)を吐く。 ビームと同じ方向にRayを発射することでヒットを取っている。 Playerのスクリプト(血パーティクルは事前にPrefabにしてから登録) va…

GUI

function OnGUI () { if (GUI.Button (Rect (10,10,150,100), "I am a button")) { print ("You clicked the button!"); } create emptyしたものにこのスクリプトをドラッグすれば表示されます。 function OnGUI () { if (GUI.Button (Rect (10,10,100,50), …

update wait ウェイト 一定間隔 インターバル

yield WaitForSeconds(5.0);var spawnOBJ : GameObject; private var busy = false; //プライベート変数はこのスクリプト内でのみ参照できる変数で、インスペクター上でも表示されません function DoSpawn () { if (!busy){ busy = true; yield WaitForSecon…