15
9

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Unity C# エラーはまりポイント

Posted at

Unityでゲームの実装をしていて、何度も同じエラーに苦しめられたので、メモ書き程度にまとめていきます(随時更新)

Vector3ではまる

Cannot modify a value type return value of `UnityEngine.Transform.position'. Consider storing the value in a temporary variable

このエラーに非常に苦しめられました。

これは、

GameObject.transform.position.x = pos.x;

と直接position.xに数値を入れようとするとエラーになるらしく、

Vector3 tempSpear = GameObject.transform.position;
temp.x = pos.x;
spearObj.transform.position = temp;

と一度Vector3に入れて、再度positionを当てなおしてやるとエラーが解消されました。これはハマった。。。

GetComponentではまる

Cannot convert method group `GetComponent' to non-delegate type `Robot'. Consider using parentheses to invoke the method

GetComponentが怪しいなーと思いつつ、これは

GameObject.GetComponent<Robot>;

こう書いていたのが、

GameObject.GetComponent<Robot>();

こうでした。()か。。。

※随時更新

15
9
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
15
9

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?