Quantcast
Channel: HAPPY*TRAP » Unity
Browsing latest articles
Browse All 10 View Live

[Unity] public変数をInspectorビューに表示しない

publicな変数をInspectorビューに表示したくない場合は、 HideInInspector属性を指定します。 [C#] using UnityEngine; using System.Collections; public class example : MonoBehaviour { [HideInInspector] public int hoge; }

View Article


Image may be NSFW.
Clik here to view.

[Unity] Mac環境でprintメソッドやGUIクラスのメソッドを使用した際の日本語文字化け問題の対処法

Mac環境でprintメソッドやGUIクラスのメソッドを使用して日本語を出力すると 文字化けます。 [C#] using UnityEngine; using System.Collections; public class example : MonoBehaviour { void OnGUI () { if (GUI.Button(new Rect(Screen.width / 2,...

View Article


Image may be NSFW.
Clik here to view.

[Unity][Blender]オブジェクトのエッジをシャープにする

Blenderで作成したオブジェクトをUnityにインポートしてみたら、 オブジェクトのエッジにスムージング処理がかかってました。 Unity側にスムージング処理の設定が見当たらなかったので、 Blender側でEdge Splitモディファイアを追加することでシャープにしてみました。 [Blender] オブジェクトを選択 > プロパティウィンドウからモディファイアメニューを表示 >...

View Article

Image may be NSFW.
Clik here to view.

[Unity] Blenderからオブジェクトを簡単にインポートする

Unityのプロジェクトフォルダ内にあるAssetsフォルダに、 .blendファイルを置くだけで自動的にインポートしてくれます。 例えば、以下のようなオブジェクトをBlender側で作成したとします。 これを「cube.blend」というファイル名で、Assetsフォルダ内に保存します。 これでUnityのProjectパネル内にcubeのオブジェクトとマテリアルが追加されます。...

View Article

[Unity] GameObjectにアタッチされたコンポーネントを参照する

GameObjectにアタッチされたコンポーネントを参照するには、GetComponentメソッドを使用します。 ※サンプルコードはC#です。 例1.BallオブジェクトにアタッチされたSphereコライダを取得 GameObject ball = GameObject.Find("Ball"); SphereCollider ballCollider =...

View Article


[Unity] Physics.Raycastを使用してオブジェクトが接地しているか判定する

Physics.Raycastを使用して、球(Ball)が地面(Ground)に接地しているかを判定してみます。 ※球にはSphereColliderがアタッチされているものとします。 [C#] using UnityEngine; using System.Collections; public class Ball : MonoBehaviour { SphereCollider...

View Article

[Unity] オブジェクトの表示、非表示

※サンプルコードはC#です。 表示 renderer.enabled = true; 非表示 renderer.enabled = false; また、iTweenライブラリを使用するとフェードイン、フェードアウトも簡単に 実装できます。 フェードイン iTween.FadeTo(gameObject, iTween.Hash("alpha", 1, "time", .5f)); フェードアウト...

View Article

[Unity] 物理演算で動いているオブジェクトを停止させる

Rigidbodyに力を加えて動かしたオブジェクトを停止させる方法です。 [C#] rigidbody.velocity = Vector3.zero; rigidbody.angularVelocity = Vector3.zero; 回転しているオブジェクトの場合は、angularVelocityも忘れずにゼロにします。

View Article


[Unity] 3次元における2点間の距離

3次元における2点間の距離を求めるにはVector3クラスのDistanceメソッドを 使用します。 [C#] // target1オブジェクトとtarget2オブジェクトの距離 float distance = Vector3.Distance(target1.transform.position, target2.transform.position);

View Article


[Unity] 任意の時間(秒)処理を止める

任意の時間(秒)待機したい場合は、WaitForSecondsが便利です。 [C#] private IEnumerator GameOver() { print("Game Over!!"); // 2秒間待機 yield return new WaitForSeconds(2); Application.LoadLevel("Title"); }...

View Article
Browsing latest articles
Browse All 10 View Live