2014年7月27日日曜日

OrthelloのAnimatingSpriteでアニメーション画像を変更する [Unitty Orthello C#]

TextureとOTAnimationはそれぞれドラッグ&ドロップで配置すること

//変数宣言
int AnimationNo = 4;

public Texture PlayerTex4;
public Texture PlayerTex5;
public Texture PlayerTex7;
public OTAnimation PlayerAni4;
public OTAnimation PlayerAni5;
public OTAnimation PlayerAni7;
Texture PlayerTex;
OTAnimation PlayerAni;

//アニメーション選別
if (AnimationNo == 4) {
PlayerTex = PlayerTex4;
PlayerAni = PlayerAni4;
} else if (AnimationNo == 5) {
PlayerTex = PlayerTex5;
PlayerAni = PlayerAni5;
} else if (AnimationNo == 7) {
PlayerTex = PlayerTex7;
PlayerAni = PlayerAni7;
}

//アニメーション入れ替え
OT.AnimatingSprite("Player").spriteContainer.texture = PlayerTex;
OT.AnimatingSprite("Player").animation = PlayerAni;

2014年6月11日水曜日

Unityで文字列関連 [Unity C#]

●指定文字が文字列に含まれているか

int iNos = 文字列.IndexOf('D');

含まれている場合は位置の数値を返す。
含まれていない場合は-1を返す



●指定文字列が文字列に含まれているか
bool ans = 文字列.Contains("DDDDDD");

含まれている場合、true
含まれていない場合、false

※indexOfの場合はcharなのでシングルクォートで囲むこと、そうしないとエラーになる


●文字列中に指定文字がいくつ含まれているか
string aData = "A_B_C_";
int Cou = aData.Split(new char[] {'_'}).Length - 1;
Debug.Log ("Cou : " + Cou.ToString ());

結果:Cou : 3

プレハブでインスタンス生成時に子オブジェクト一覧を取得する [Unity C#]

子オブジェクト一覧を取得する

int iCount = transform.childCount;

bool ansTop = false;
bool ansButtom = false;

string Top = "";
string Buttom = "";

void Start () {
for(int i=0; i<iCount; i++){
Transform child = transform.GetChild (i);
Debug.Log("ObjectName : " + child.name);

if (ansTop) {
Top = child.name;
Debug.Log("Top : " + Top);
ansTop = false;
} else if (ansButtom) {
Buttom = child.name;
Debug.Log("Buttom : " + Buttom);
ansButtom = false;
}
}
}




2014年6月10日火曜日

UnityでPNG画像のグラデーションがひどい場合の対処法 [Unity Gimp]

Unityで使用しているPNG画像のグラデーションがひどかったので調べてみた。

通常のPNGはRGBA32bitでUnityで使用するときにRGBA16bitに変換されるらしい。

対処法
①Gimp2でスクリプトを作成してくれた人がいるらしいのでそれを利用する
②「dither16bit.scm」「Gravscales.zip」をダウンロード
③「dither16bit.scm」をGimpのユーザフォルダの「scripts」にコピー
④「Gravscales.zip」を解凍して全ての「.gpl」ファイルをGimpのユーザフォルダの「palettes」にコピー


使い方
「画像」-「モード」-「Dither to ARGB 4444」を選択すると勝手に変換してくれる。
※保存を忘れずに




参考サイト
RGBA4444に変換できるツール
Unityやるには必須!RGBA画像現職の基本をまじめに書いてみた

ありがとうございました

2014年6月2日月曜日

エクセル Excel 関連 [Excel]

1.行の高さを自動調整する

ツールバーの[書式]-[行]-[行の高さの自動調整]を選択すると自動調整される

※セルの連結してるとならないっぽい
※ツールバーとは上のほうに[ファイル][編集][表示][挿入][書式]...とか表示されている個所のこと

三角関数 角度を求める [Unity C#]

球の発射系では発射位置が固定されていると思うが、その際に発射角度を求めたい場合。

float Angle;
float x;
float y;

//角度を求める
Angle = Mathf.Atan ( y / x ) * Mathf.Rad2Deg;

//対象の角度を変更
対象.transform.localRotation = Quaternion.Euler(0,0,angle);

で角度が変更出来る



2014年5月30日金曜日

オブジェクトのコンポーネント(Script)を取得 [Unity C#]

スクリプト名「SampleClass」
SampleClassの変数宣言
public string str = "";

//親オブジェクトを取得
GameObject objParent = this.transform.parent.gameObject;
//親オブジェクトのコンポーネント(Script)を取得
SampleClass SC = objParent.GetComponent<SampleClass>();
SC.str = "AAA";



2014年5月14日水曜日

子オブジェクトの取得 [Unity C#]

//オブジェクト取得
GameObject Play1;
Play1 = GameObject.Find("Character1");
Play1.transform.localPosition = new Vector3(0 , 0 , 0);

//子オブジェクト取得
GameObject Play2;
Play2 = GameObject.FindChild("Character").gameObject;
Play2.transform.localPosition = new Vector3(0 , 0 , 0);


など

2014年4月18日金曜日

親オブジェクトの取得 [Unity C#]


GameObject Parent;
Parent=  gameObject.transform.parent.gameObject;


2014年4月16日水曜日

数値の正・負の符号を反転させる [Unity C#]

■ケース1
Debug.Log ((5).ToString ());
Debug.Log (-(5).ToString ());
◆結果
5
-5


□ケース2
Debug.Log ((-5).ToString ());
Debug.Log (-(-5).ToString ());
◇結果
-5
5

2014年4月14日月曜日

Unityで一時停止処理 [Unity C#]

ゲームの最中に一時停止を行う方法(Physic)

1.Time.timeScaleを0に設定
 Time.timeScale = 0;

2.Physic以外の処理を停止させたい場合は
 各動作処理の際にTime.timeScale>0を追加する
 Time.timeScaleが0以上の場合に処理(動作させる)を行う


上記で一時停止となる。

2014年2月9日日曜日

SCMPXでmp3ファイルをWAVファイルに変換する

1.「CONVERT」‐「Single file」-「Decode to wav」を選択。
2.対象のmp3ファイルを選択
3.保存するwavファイル名を指定

※Web上で変換出来るサイトとかあったけどうまく変換できなかったりしたので、変換ソフトとしてはこのソフトが一番簡単で良かった

2014年2月8日土曜日

文字列を数値変換 [Unity C#]

文字列を数値に変換する際

string str = "1234";

int i = (int)str;

とすると「 error CS0030: Cannot convert type `string' to `int'」と怒られます。

これを↓こうすると怒られません

int i = int.Parse(str);



2014年2月5日水曜日

レイヤーベースの衝突検出 [Unity]

RigidBodyを設定しているオブジェクト同士で衝突させない方法

※キャラクターと背景の雲を衝突させたくない場合など

1.レイヤーを作成する
 「Inspector」-「Layer」-「Add Layer」を選択し、あいている個所に作成するレイヤーの名前を入力する

2.対象となるオブジェクト(ここでは雲)を作成したレイヤーに設定する
 「Inspector」-「Layer」-「1で作成したレイヤー


で完成


異なるレイヤーに属している場合は衝突検出しなくなります。

ここを参考にしました。



2014年2月3日月曜日

バウンド [Unity]

1.新規で「Physic Material」を作成

2.対象オブジェクトの[Collider]-[Material]に1で作成した「Physic Material」を追加(選択)

3.1で作成した「Physic Material」を選択し、「Inspector」-「Bounciness」を設定。(数値)


ここを参考にしました

衝突判定 [Unity C#]

void OnCollisionEnter(Collision collis) {

//衝突した相手の名前を取得
Debug.Log(collis.gameObject.name);

//衝突時の相対速度
Debug.Log(collis.relativeVelocity);

}

乱数 [Unity C#]



Random.Range (min , max);

2014年1月16日木曜日

重力加速度設定 [Unity C#]


float gX = 0.0f;
float gY = -100.0f;
float gZ = 0.0f;

Physics.gravity = new Vector3(gX , gY , gZ);