Unity 全般

transform.localScale

親オブジェクトのスケールを変化させても子オブジェクトを変化させたくない場合 - テラシュールブログtsubakit1.hateblo.jp

【Unity】onClick : スクリプトから変更 (onClick.AddListener)

例1(問題有の可能性) //(名前空間の定義) //using UnityEngine.Events; if((SituationCreater2.instance.Count) < 10){ button = ObjectFromToilet.GetComponent<Button> (); if (n < 1){ // ObjectFromToilet.GetComponent<Image>().sprite = null; }else if(1 < n && n </image></button>…

画面のタップを取得する

if ((Input.touchCount >0&& Input.GetTouch (0).phase == TouchPhase.Began )|| Input.GetMouseButtonDown(0)) { http://albatrus.com/main/unity/6520 UnityでAndroidのタッチ操作 - tanaka's Programming Memoam1tanaka.hatenablog.com

画面の向きを決める

「BuildSetting」「PlayerSetting」「Resolution and Presentation」「Default Orientation」 縦向き:Portrait 横向き:Landscape Left起動時の画面の向きを固定する | nekosukoブログnekosuko.jp

【Unity エラー】CS0161 : コルーチンで"return"がない

コルーチンに設定して、"return"がない。 error CS0161: `SituationManager.DoorOpenWait()': not all code paths return a value public void OpenDoor(){ isDoorOpen = true; print("Open Door"); SituationChara = TempSituation; StartCoroutine(DoorOpe…

色Vector4

// 赤 SliderLife.gameObject.transform.FindChild("FillArea").GetComponentInChildren<Image>().color = new Vector4(0, 0, 1, 1); // 青 SliderLife.gameObject.transform.FindChild("FillArea").GetComponentInChildren<Image>().color = new Vector4(1, 0, 0, 1);</image></image>

GetComponent<TextMesh>().color = Color.blue

Case[Type].transform.FindChild("TimerGameOver"). gameObject.GetComponent<TextMesh>().color = Color.blue; 3D Text - How to change colour - Doesn't seem to work - Unity Answers</textmesh>

Buttonプレス時にSpriteを変えたい時

TransitionをSprite Swapに設定する。Unity - マニュアル: 遷移オプションdocs.unity3d.com

子要素の兄弟関係にあるオブジェクトを取りたい時

SituationManager tempSituationManager; GameObject Parent = hit2.transform.parent.gameObject; tempSituationManager = Parent.transform.GetComponentInChildren<SituationManager>(); Unityの親子。★transform.parent とgameObject - 149cmプログラマ-unity3d.hatenablog</situationmanager>…

Spriteの設定

・Filter Mode 引き伸ばした時のぼかし方の設定。 ピクセルアートにしたい時、Pointにする。・Generate Mip Maps 2Dのときは、オフにする。テクスチャで設定できる項目 - テラシュールブログtsubakit1.hateblo.jp Unity テクスチャ(Texture 2D)の基本設定 -…

Touchの扱い

void TouchFingerInput(){ if (Input.touchCount > 0){ Touch touch = Input.touches[0]; // フェイズで管理できる。 switch(touch.phase){ // タッチ開始場所 case TouchPhase.Began: OnStartDrag(touch.position); break; // タッチ終了場所 case TouchPha…

Time.timeScale(ポーズ画面)

// ポーズ画面静止状態にする public void PopPaused(){ GameManager.instance.Play = false; PausedParent.SetActive(true); Time.timeScale = 0; } public void HidePaused(){ GameManager.instance.Play = true; PausedParent.SetActive(false); // 元の…

Touch touch = Input.GetTouch(0);

【Unity 2D】GameObjectにタッチ処理を実装するalbatrus.com Unity - 入力 / Inputpsm.playstation.net

オブジェクトの親子関係(孫要素)

//オブジェクトの孫要素を取得する。 EndScreen.transform.FindChild("ScoreParent").transform.FindChild("Score").GetComponent<Text>().text =""+ (SituationCreater.instance.Count); // わざわざFindChildを使う非有ようがないのであれば、以下でよい。 GameO</text>…

GetComponent<TextMesh>().text

UIでなくて、文字を表示する方法 //public string text ScenePrefabs[Type].transform.FindChild("OddNumberWC").GetComponent<TextMesh>().text = "" + (Count + ScenePrefabs.Length); GameObject上にカウントダウンテキスト表示するにはja.stackoverflow.com Unity</textmesh>…

【Unity】Screen.width : 画面サイズの取得方法

unity_get_screen_size - FreeStyleWiki

CanvasのRender Cameraをスクリプトで変更したい(覚える)

o.transform.FindChild("Canvas").GetComponent<Canvas>().worldCamera = targetCamera; //例2 //メインカメラの最初の名前は、「Main Camera」になっている。 //「MainCamera」に変更しないといけない。 CanvasSituation.GetComponent<Canvas> ().worldCamera = GameObject</canvas></canvas>…

2Dでスワイプ(フリック)を取得する方法

Rayを使って、最初と最後の入力の位置を獲得して、自分でRayを定義してあげる。 (スワイプの取得方法で、他にいい方法があれば教えて欲しいです。) using UnityEngine; using System.Collections; using UnityEngine.UI; public class FlickManager : Mono…

ベクトルの角度

//y軸との角度を取得する。 float angle =Vector2.Angle(new Vector2(0,1),UnitVector); Vector3クラスのメモ - unity学習帳unitylab.wiki.fc2.com

色を使って変化

iTweenを使って、色を変化させる。 iTween.ColorTo(Background_White,iTween.Hash("r",1f, "g",1f, "b",1f, "time",0.5f));

オブジェクトの生成、UpdateよりCoroutine

Updateでオブジェクト生成のメソッドを書くより、StartCoroutineを使って生成する方が早くなる。(理由は・・・)Coroutineとwhileを使ってオブジェクトを生成する。 using UnityEngine; using System.Collections; public class Interpolator3 : MonoBehavi…

二点間の単位ベクトル

UnitVector = ( Obj2.transform.position - Obj1.transform.position ).normalized; 3D+ Unity 二点間のベクトル3dplus.blog.fc2.com

2点間の距離を取る。

public static float Distance(Vector2 a, Vector2 b); ActionScript入門Wiki - Unity - (Vector3)二点間距離を求める Unity - スクリプティング API: Vector2.Distancedocs.unity3d.com

ScreenToWorldPoint(2D上でお絵描きしたいとき)

2Dでの「Camera.main.ScreenToWorldPoint」の扱いに困った。 これは、「スクリーン座標をワールド座標に変換する関数」であるが、これを2Dで使うたいとき、カメラのプロパティ「Projection」を「Orthographic」(2D用)に設定してあげなければならない。082…

RigidbodyとColliderの干渉

Rigidbodyコンポーネントを持つオブジェクトを、Colliderコンポーネントを持つコンポーネントの上に生成すると、反発する。もし共存させたい場合は、レイヤーを設定して、「PlayerSetting」「Physics」のところで、レイヤーの影響範囲を設定してあげる。

Application.OpenURL()

UntiyでWebページを開きたい時に使う。 public void ShareButton(){ Application.OpenURL("https://www.google.co.jp"); } Unity3D:アプリのレビューページを直接開く - devlog [naru design] Unityアプリからソーシャルメディアと連携する - Qiitaqiita.com…

【Unity エラー】CS0029 : 変数型違いによるエラー

ケース1 エラー内容 error CS0029: Cannot implicitly convert type `UnityEngine.Transform' to `UnityEngine.GameObject' 修正前 public GameObject ClearScreen; GameObject ClearHideButton; public void ClearStage(){ ClearHideButton = ClearScreen.…

シーンを読み込んだ時の初期状態に戻す

再度シーンを読み込むことによって、リロードすることができる。 オブジェクトの初期状態を変数に入れておいて、元に戻すという手間なことをする必要がない。 Application.LoadLevel("Stage1"); Unity C# リロード(初期状態にもどる)的な処理 - Qiitaqiita…

UIはEventSystemがないと動かない

複数のステージを作る際に、Canvasをプレハブで再利用するとき、EventSystemを子にしておく。

transform.SetParent

親を設定する。 cameoChild.transform.SetParent(ListParent.transform);