【Unity エラー】CS0029 : 変数型違いによるエラー
ケース1
エラー内容
error CS0029: Cannot implicitly convert type `UnityEngine.Transform' to `UnityEngine.GameObject'
修正前
public GameObject ClearScreen; GameObject ClearHideButton; public void ClearStage(){ ClearHideButton = ClearScreen.transform.FindChild("ClearHideButton"); }
修正後
public GameObject ClearScreen; GameObject ClearHideButton; public void ClearStage(){ ClearHideButton = ClearScreen.transform.FindChild("ClearHideButton").gameObject; }
GameObjectの子要素・親要素を取得する - Neareal
ケース2
修正前
//2次元と1次元 rigidbody2D.velocity = Random.Range(0.3f,-0.3f);
修正後
//2次元と2次元 rigidbody2D.velocity = new Vector2(0,Random.Range(0.3f,-0.3f));
Compiler Error CS0029 | Microsoft Docs
rigidbody2D.velocityについて
[Unity]Unity4.3の2Dツールを使ってみる -Physics2Dスクリプト編その2- | クスールブログ
ケース3
エラー内容
文字型stringをbool型に変換できませんと...。
error CS0029: Cannot implicitly convert type `string' to `bool'
修正前
if(col.gameObject.transform.tag = "floorBelow"){ floor_Below = true; }
修正後
if(col.gameObject.transform.tag == "floorBelow"){ floor_Below = true; }
比較演算子は、「==」を使う