LoginSignup
1
0

More than 5 years have passed since last update.

Unity初心者やってみた5

Posted at

前回:https://qiita.com/akagane99/items/0d01e4b21919278f5469
次回:
一覧:https://qiita.com/akagane99/items/2dd005511a8d50f5634d

(前回の続き)

バグ対応:コイン出るとこ壁にめり込む2

キーボードの←→で壁にめり込む。こうなる。
https://akagane99.github.io/WebGLGames/coin4/

下記箇所に値を直指定。
キャストしないと、セットできなかったけど、Microsoft Visual Studioがヘルプメッセージで
ヒント表示してくれたため、解決できた。

修正コード

    void Update () {

        /* 追加
         * Mathf.Clamp である変数の最小値と最大値を設定することができる。
         * 第一引数は設定したい変数、第二引数は最小値、第三引数は最大値である。
         * Spawner の移動できるx 座標範囲をleftWallPosition のx 座標から、rightWallPostion のx 座標の範囲にしている。
         */
        Vector3 currentPosition = this.transform.position;
        currentPosition.x = Mathf.Clamp(currentPosition.x,
                                        leftWallPositionX + (float)0.5,
                                        rightWallPositionX - (float)0.5);
(省略)
     }

Microsoft Visual Studioのヘルプメッセージ例

image.png

ここまでできた

// 行動予定・行動結果

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