ここまでで

ができました!!

早速切ったブランチでこれまで習った内容(commit,push,merge)を復習しながら作業を行っていきます!

今回は球体を矢印キーで操作できるようにするという簡単な内容で進めていきます

復讐編

実際にunityで作業する道中でバージョン管理の流れを復習していこう!

  1. 該当のunityプロジェクトを立ち上げる

  2. ヒエラルキーにPlaneSphereを追加する

    image.png

  3. GitHub Desktopの方に変更点が反映されていればOK!commitしよう!

  4. Publish branchをクリックしてローカルのブランチをリモートにも追加して、変更内容のpushも行います

    スクリーンショット 2024-12-29 013158.png

  5. SphereのTransformInspectorからY座標のみ0.5に変えておく

    image.png

  6. Add ComponentNew scriptPlayerControllerという名前でCreate and Add

    image.png

  7. 以下のコードを今作成したスクリプトにコピペする

    using UnityEngine;
    
    public class BallController : MonoBehaviour
    {
        public float moveSpeed = 5f; // 移動速度
    
        private Rigidbody rb;
    
        void Start()
        {
            // Rigidbody コンポーネントを取得
            rb = GetComponent<Rigidbody>();
    
            if (rb == null)
            {
                Debug.LogError("Rigidbodyがアタッチされていません!");
            }
        }
    
        void FixedUpdate()
        {
            // 矢印キーの入力を取得
            float moveHorizontal = Input.GetAxis("Horizontal"); // 左右キー
            float moveVertical = Input.GetAxis("Vertical");   // 上下キー
    
            // 入力に基づいて移動ベクトルを計算
            Vector3 movement = new Vector3(moveHorizontal, 0.0f, moveVertical);
    
            // Rigidbodyを使用して球を移動
            rb.AddForce(movement * moveSpeed);
        }
    }
    
  8. Sphereに RigidbodyAdd Componentで追加する

    image.png

  9. ctrl+sで保存しておく(これをしないとGitHubの方に変更が反映されない)