Unity 全般

Splashスクリーンのフェイドアウトの例

using UnityEngine; using System.Collections; using UnityEngine.UI; public class SplashScreenScript : MonoBehaviour { public Image myPanel; float fadeTime = 2f; Color colorToFadeTo; void Start() { colorToFadeTo = new Color (1f, 1f, 1f, 1f);…

PlayerPrefsのデータをすべて消して動作確認

if (Input.GetKeyDown(KeyCode.A)){ PlayerPrefs.DeleteAll(); } Unityで、保存データ全消しのデバッグ用ボタンを配置するblog.k-kansei.com

レベルの管理について(ハイスコアと同じ要領)

レベルの管理ってどうしたらいいのだろう。 以下のスクリプトで管理することはできるが、何かいい方法があれば教えて欲しいです。 using UnityEngine; using System.Collections; public class LevelManager : MonoBehaviour { public int CurrentLevel; pub…

GridLayoutGroup

全て同じ要領で、プロパティを参照することができる。 間違っていると思うときは添付して検索。 float GridSpace = Content.GetComponent<GridLayoutGroup>().spacing.y;</gridlayoutgroup>

Canvas Scaler

UIを使うとき、「Canvas Scaler」を「scale with screen size」に設定するようにする。

オブジェクト.active

オブジェクトがアクティブか非アクティブをbool型のtrue・falseで返す。 public void HomeButton(){ // ホーム画面に戻る操作。 Application.LoadLevel("Home"); play = false; if(ClearScreen.active = true){ ClearScreen.SetActive(false); } } Unityゲー…

Sceneでオブジェクトが消えないようにする。

シーンを切り替えても、オブジェクトが消えないようにする。 using UnityEngine; using System.Collections; public class GameManager : MonoBehaviour { void Awake(){ DontDestroyOnLoad(this.gameObject); } } Unity - Scene切替時でもGameObject等を破…

hit.transform.gameObject.layer

RaycastHit2Dのlayerを参照したい。 hit. transform. gameObject. layer http://docs.unity3d.com/ja/current/ScriptReference/RaycastHit2D.html 公式のページから、RaycastHit2Dは、 transformのプロパティを持っていることわかる。 transformからgameObje…

Physics2D.Raycast

3D用の当たり判定は2D用では使えない。 コードを2Dように書く必要がある。2D用、例1 using UnityEngine; using System.Collections; public class ObjectManager3 : MonoBehaviour { public GameObject Prefab; void Start () { } void Update () { if(Inp…

面白い、軌跡のオブジェクトを生成

is4cafe.hatenablog.com

Input.mousePosition

マウスで押した場所を取得する。ActionScript入門Wiki - Unity - クリックした位置にオブジェクトを移動させるwww40.atwiki.jp

【Unity】rectTransform.localPosition : 使用例

UIコンポーネントの位置は、rectTransformで扱うことができる。 public class CreditController : MonoBehaviour{ public Text CreditMainText; public void PopCredit(){ CreditMainText.rectTransform.localPosition = new Vector3(0f,-200f,0f); } } スク…

【Unity】オブジェクト ドラッグで移動

オフセットの部分は、ベクトルで考えるとわかりやすい。 using UnityEngine; using System.Collections; public class PieceManager : MonoBehaviour { private bool isDrag = false; enum STEP{ NONE = -1, IDLE = 0, DRAGGING, } // 初期状態 private STEP…

Raycast,C#でサンプル

using UnityEngine; using System.Collections; public class CubeManager : MonoBehaviour { public static CubeManager instance = null; void Awake(){ if(instance = null){ instance = this; } } void Update () { if( this.gameObject == GameManager.…

Vector3.Distance(A, B) もしくは、(pos1 - pos2).magnitude

A,B間の距離を計算してくれるプロパティ float型で値を返す。 // Bool型のメソッド。メソッドも返り血をBool型することもできる。 private bool is_in_snap_range() { bool ret = false; // ある程度離れていたとしても、trueとする。 if(Vector3.Distance(t…

ray.origin, ray.direction

originプロパティ:開始点 directionプロパティ:方向(単位ベクトル) public bool unproject_mouse_position(out Vector3 world_position, Vector3 mouse_position) { // returnでtrue、falseを返す。 // ret、ローカル変数にする。 bool ret; float depth…

オーディオをサンプルスクリプト

Unity – 効果音(SE)を再生する方法。複数の音を鳴らすサンプルコードも用意しました | increment Logincrement-log.com

コンポーネントを取得

コンポーネントを取得するとき、2通りの書き方がある。 public GameObject textlevel_ex; public text textlevel; textlevel = textlevel_ex.GetComponent<Text>(); public void TextLevel(string method){ if(method == "pop"){ ParentChance.SetActive(true); t</text>…

ハイスコア

ハイスコアの作成は、Unity公式チュートリアルを参考にした。Unity: 統合ゲーム開発環境japan.unity3d.com using UnityEngine; using System.Collections; using UnityEngine.UI; // プレイ画面でのスコアの表示 public class Score : MonoBehaviour { publi…

JsonDataはカウントすることができる。

private void LoadAbilityTableFromJSON(string json) { JsonData jresult = JsonMapper.ToObject (json); List<Questions> data = new List<Questions> (); // JsonDataはカウントすることができる。 maxQuestion = jresult.Count; for(int i=0;i</questions></questions>

FixedUpdate()

オブジェクトに物理運動をさせるときは、FixedUpdateを使う。 void FixedUpdate (){ if(GameManager.instance.play){ float horizontal = Input.GetAxis("Horizontal"); // 速度上限を決める if(rigidbody2D.velocity.x > minWalkForce && rigidbody2D.veloc…

JSONとは?

Wikipedia データ記述言語の1つである。構文はJavaScriptにおけるオブジェクトの表記法をベースとしているが、JSONはJavaScript専用のデータ形式では決してなく、様々なソフトウェアやプログラミング言語間におけるデータの受け渡しに使えるよう設計されてい…

LitJSONの使い方

わかりやすい。LitJsonにて C# Unity - 万年素人からHackerへの道shinriyo.hateblo.jp naochang | UnityでJsonを扱う・LitJSON Quickstart(英語) Guide LitJSON Quickstart Guide・Convert CSV To JSON CSVデータをJSONに変換(これは便利!)CSV To JSON …

Audioはどこに?

AudioSourceにまとめることもできるけど、 オブジェクトのスクリプトに付けることもできる。(以下のように) using UnityEngine; using System.Collections; public class Evolve_Room : MonoBehaviour { public GameObject BackgroundRoom; public GameObj…

端末を回転させた際の画像の向き

端末を回転させた際の画面の向きを固定する - テラシュールブログtsubakit1.hateblo.jp

【Unity】オブジェクトのSetActive(false)に関して

他のスクリプトからSetActive(false);でオフにしたオブジェクトは、Awakeで呼び出されなくなる。 例えば、PlayerPrefsを呼び出したいのに、このブジェクトをオフにしたら、呼び出されない。 void Awake(){ if(instance ==null){ instance = this; } // Audio…

【Unity】RectTransform : localPosition, positionは違うもの

localPosition、positionは別物。 public void LeftControl(){ ForceButton.gameObject.GetComponent<RectTransform>().localPosition = DefaultPosForceButton; } public void RightControl(){ // localPositionと記述してあげなければ、グローバルな場所になる。 ForceBut</recttransform>…

Unityの50Tips

いたるところで紹介されているhttp://warapuri.com/post/28972633000/unity開発に関する50のtips-ベストプラクティス翻訳warapuri.tumblr.com

AddComponent

//型指定 gameObject.AddComponent<Rigidbody>(); //文字列指定 「””」で囲ってあげなければならない。 gameObject.AddComponent("Rididbody"); ActionScript入門Wiki - Unity - プログラム側からコンポーネントを追加するwww40.atwiki.jp</rigidbody>

Google Analytics

初心者のためのGoogle Analytics(アナリティクス)講座!analytics.gary01.com