0
0

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 3 years have passed since last update.

【Unity】[エラー]コンポーネント追加時に Can't add script

Last updated at Posted at 2022-05-12

どういうことか

Unityを学習している。
こちらの記事を参考に、スクリプトを書いてコンポーネントの追加をしようとしたら掲題のエラーが出た。

エラー文でググってみたら「ファイル名とクラス名で不整合があるとダメだよ」ということがわかったが、自分の場合はその不整合がなかった。

原因

おわかりだろうか。

    void Update() {
       if (Input.GetKey(KeyCode.LeftArrow)) {
           transform.position += transform.foward * 0.1f;
       } else if (Input.GetKey(KeyCode.RightArrow)) {
           transform.position -= transform.foward * 0.1f;
       }
    }

そう、foward が間違っている。forwardが正しい。
なので下のコードに直したらエラーが出ずに追加することができた。

    void Update() {
       if (Input.GetKey(KeyCode.LeftArrow)) {
           transform.position += transform.forward * 0.1f;
       } else if (Input.GetKey(KeyCode.RightArrow)) {
           transform.position -= transform.forward * 0.1f;
       }
    }


この間違いは気づきにくい。。
Xcodeだと直してくれそうだけど、VSCodeでC#の機能拡張入れても特に警告とか自動補完とか無くて全然気づくことができなかった。
VSCodeでPHP書いてるときもこんな感じだったっけか。。もう自動補完がない感覚を忘れてしまった。

0
0
0

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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?