Y N
    • Create new note
    • Create a note from template
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Write
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Engagement control Commenting, Suggest edit, Emoji Reply
    • Invite by email
      Invitee

      This note has no invitees

    • Publish Note

      Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note No publishing access yet

      Your note will be visible on your profile and discoverable by anyone.
      Your note is now live.
      This note is visible on your profile and discoverable online.
      Everyone on the web can find and read all notes of this public team.

      Your account was recently created. Publishing will be available soon, allowing you to share notes on your public page and in search results.

      Your team account was recently created. Publishing will be available soon, allowing you to share notes on your public page and in search results.

      Explore these features while you wait
      Complete general settings
      Bookmark and like published notes
      Write a few more notes
      Complete general settings
      Write a few more notes
      See published notes
      Unpublish note
      Please check the box to agree to the Community Guidelines.
      View profile
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Note Insights New
    • Engagement control
    • Make a copy
    • Transfer ownership
    • Delete this note
    • Save as template
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Note Insights Versions and GitHub Sync Sharing URL Create Help
Create Create new note Create a note from template
Menu
Options
Engagement control Make a copy Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Write
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Engagement control Commenting, Suggest edit, Emoji Reply
  • Invite by email
    Invitee

    This note has no invitees

  • Publish Note

    Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note No publishing access yet

    Your note will be visible on your profile and discoverable by anyone.
    Your note is now live.
    This note is visible on your profile and discoverable online.
    Everyone on the web can find and read all notes of this public team.

    Your account was recently created. Publishing will be available soon, allowing you to share notes on your public page and in search results.

    Your team account was recently created. Publishing will be available soon, allowing you to share notes on your public page and in search results.

    Explore these features while you wait
    Complete general settings
    Bookmark and like published notes
    Write a few more notes
    Complete general settings
    Write a few more notes
    See published notes
    Unpublish note
    Please check the box to agree to the Community Guidelines.
    View profile
    Engagement control
    Commenting
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    • Everyone
    Suggest edit
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    Emoji Reply
    Enable
    Import from Dropbox Google Drive Gist Clipboard
       Owned this note    Owned this note      
    Published Linked with GitHub
    2
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    # ゲーム仕様の実装 Part1 報告遅くなりたいッッッへん申し訳ないです、、(土下座の絵文字) 正直何したらいいかわからなかったので少しでもゲームっぽくなる&物理組が物理演算系を少しでも考えやすくなるようにいろいろ追加しました! 今後も何か思いついたら追加する予定です。 まずは、UIの方が大変なのでこちらもボタンの紐付けをやってみようと思います(グッ!の絵文字) ## 更新 8/12 ・球の軌道の追加 ・クリックしたら球が動く仕様追加 8/16 ・球の無限生成 10/6 ・タイトル画面作成(タイトル画面デザイン要相談) comming soon... <br> ## 実装コード <details><summary>1.軌道が描けるように</summary> 軌道が可視化できたら物理運動考えやすいかな〜と思い、球の軌道を実装してみました。 <details><summary>以下追加コード↓</summary> //SphereController.csコード追加 using System.Collections; using System.Collections.Generic; using UnityEngine; public class SphereController : MonoBehaviour{ private Rigidbody rb; // *** 追加部分開始 *** private LineRenderer lineRenderer; private List<Vector3> positions = new List<Vector3>(); // 軌道の点を記録するリスト // *** 追加部分終了 *** // Start is called before the first frame update public void Shoot(Vector3 dir) { if (rb != null) { rb.AddForce(dir); // *** 追加部分開始 *** positions.Clear(); // 軌道の記録をクリア lineRenderer.positionCount = 0; // LineRendererの点の数をリセット // *** 追加部分終了 *** } else { Debug.LogError("Rigidbody component is missing from the Sphere object."); } } void Start() { rb = GetComponent<Rigidbody>(); // *** 追加部分開始 *** lineRenderer = GetComponent<LineRenderer>(); // *** 追加部分終了 *** if (rb == null) { Debug.LogError("Rigidbody component is missing from the Sphere object."); } else { Application.targetFrameRate = 60; Shoot(new Vector3(0, 200, 200)); } } // Update is called once per frame void Update() { // *** 追加部分開始 *** if (rb != null && rb.velocity.magnitude > 0.01f) { positions.Add(transform.position); // 現在位置をリストに追加 lineRenderer.positionCount = positions.Count; lineRenderer.SetPositions(positions.ToArray()); } // *** 追加部分終了 *** }} </details> <br> <details><summary>追加コンポーネント↓</summary> Sphereに「Add Component」で「Line Render」を追加 ![image](https://hackmd.io/_uploads/Sy9Q9_wcA.png) ※必要に応じてWidth(線の太さを調整) </details> <br> 結果: ![image](https://hackmd.io/_uploads/H1vsquD50.png) ↑Shoot(new Vector3(0, 330, 400));にするといい感じの衝突になった! </details> <details><summary>2.クリックしたら球が動く!</summary> 再生した瞬間に動くの変なのでクリックしたら球が動くようにしました! これはコード追加するだけ。 <details><summary>以下追加コード↓</summary> ``//SphereController.csに追加 using System.Collections; using System.Collections.Generic; using UnityEngine; public class SphereController : MonoBehaviour { private Rigidbody rb; private Vector3 initialPosition; public float resetDelay = 2.0f; // 玉をリセットするまでの待機時間 private bool isMoving = false; // 玉が動いているかどうかを管理するフラグ // Start is called before the first frame update public void Shoot(Vector3 dir) { if (rb != null) { rb.isKinematic = false; // Rigidbodyを物理演算に戻す rb.AddForce(dir); isMoving = true; // 玉が動いている状態にする } else { Debug.LogError("Rigidbody component is missing from the Sphere object."); } } void Start() { rb = GetComponent<Rigidbody>(); lineRenderer = GetComponent<LineRenderer>(); // 初期位置を保存 initialPosition = transform.position; if (rb == null) { Debug.LogError("Rigidbody component is missing from the Sphere object."); } else { // 玉を初期状態で固定する rb.isKinematic = true; } } // Update is called once per frame void Update() { // マウスクリックを検知 if (Input.GetMouseButtonDown(0) && !isMoving) // クリックされ、玉が動いていない場合 { Shoot(new Vector3(0, 330, 400)); // クリックしたら玉を動かす } // 衝突時に呼ばれるメソッド void OnCollisionEnter(Collision collision) { // 一定時間後に玉を初期位置に戻すコルーチンを開始 StartCoroutine(ResetBallAfterDelay()); } // 画面外に出た場合に呼ばれるメソッド void OnBecameInvisible() { // 一定時間後に玉を初期位置に戻すコルーチンを開始 StartCoroutine(ResetBallAfterDelay()); } private IEnumerator ResetBallAfterDelay() { // 指定された時間待つ yield return new WaitForSeconds(resetDelay); // 玉を初期位置に戻す transform.position = initialPosition; rb.velocity = Vector3.zero; // 速度もリセット rb.angularVelocity = Vector3.zero; // 回転速度もリセット // Rigidbodyを動かないように固定する rb.isKinematic = true; // 玉が止まっている状態にする isMoving = false; }} </details> 結果: ![image](https://hackmd.io/_uploads/rJ4eAdv9A.png) ↑再生ボタンを押しても球が動かない ![image](https://hackmd.io/_uploads/rJVD0OwcR.png) ↑画面をクリックしたら動いた </details> <details><summary>3.ボール自動生成</summary> 球が動作した後、新しい球が生成されることで何回でも球を投げることができる! <details><summary>球のプレハブ化↓</summary> もうできてる人もいるかもなのでできてる人は飛ばしてOK! このURLにやり方が書いてあります!↓ https://gamedev.kurokumasoft.com/2022/08/02/unity-prefab/#toc2 これの「プレハブのインスタンスの作り方」の「手動でプレハブのインスタンスを作る方法」まで行ってください </details> <details><summary>追加コード(SphereController .cs)↓</summary> そのまま貼り付けちゃってOK! ``` using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; public class SphereController : MonoBehaviour { private Rigidbody rb; public InputField inputX; public InputField inputY; public InputField inputZ; public Button shootButton; private LineRenderer lineRenderer; private List<Vector3> positions = new List<Vector3>(); // 軌道の点を記録するリスト public GameObject spherePrefab; // ボールのプレハブ private Vector3 initialPosition; // ボールの初期位置 private float screenBoundary = 10f; // 画面外とみなす距離の閾値 void Start() { rb = GetComponent<Rigidbody>(); lineRenderer = GetComponent<LineRenderer>(); if (rb == null) { Debug.LogError("Rigidbody component is missing from the Sphere object."); } else { Application.targetFrameRate = 60; // Rigidbodyを一時的に停止 rb.isKinematic = true; // 初期位置を保存 initialPosition = transform.position; // ボタンにリスナーを追加 shootButton.onClick.AddListener(OnShootButtonClicked); } } void OnShootButtonClicked() { float x = float.Parse(inputX.text); float y = float.Parse(inputY.text); float z = float.Parse(inputZ.text); Vector3 direction = new Vector3(x, y, z); // Rigidbodyを再度アクティブにして物理演算を有効化 rb.isKinematic = false; Shoot(direction); } public void Shoot(Vector3 dir) { if (rb != null) { rb.AddForce(dir); positions.Clear(); // 軌道の記録をクリア lineRenderer.positionCount = 0; // LineRendererの点の数をリセット } else { Debug.LogError("Rigidbody component is missing from the Sphere object."); } } void Update() { // 軌道を描く処理 if (rb != null && rb.velocity.magnitude > 0.01f) { positions.Add(transform.position); // 現在位置をリストに追加 lineRenderer.positionCount = positions.Count; lineRenderer.SetPositions(positions.ToArray()); } // 画面外チェック if (Mathf.Abs(transform.position.x) > screenBoundary || Mathf.Abs(transform.position.y) > screenBoundary || Mathf.Abs(transform.position.z) > screenBoundary) { Respawn(); } } void OnCollisionEnter(Collision collision) { if (collision.gameObject.CompareTag("Cube")) { Respawn(); } } void Respawn() { Debug.Log("Respawn called. Creating new Sphere at position: " + initialPosition); // 新しいボールを生成 GameObject newBall = Instantiate(spherePrefab, initialPosition, Quaternion.identity); Debug.Log("New ball created at position: " + newBall.transform.position); // 現在のボールを削除 Destroy(gameObject); } } ``` </details> <details><summary>Cubeにタグをつける</summary> さっきのコードがうまく作用するようにCubeたちにタグをつけます。 やり方: 1:ヒエラルキーのCubeを選択してください 2:出てきた右のメニュー画面のTagから「Add Tag」を選択して新しいタグ「Cube」を作ってください 3:先ほどの画面に戻ってTagから「Cube」を選択してください 4:Cube全てにこれを適用してください ![image](https://hackmd.io/_uploads/rJ02bv2qC.png) </details> <details><summary>Sphereをアセットする</summary> 最後にインプット欄やボタンで行ったアセットを行います。 やり方: 1:ヒエラルキーのSphereを選択してください 2:出てきた右のメニュー画面のSphere Controller(Script)に「Sphere Prefab」が表示されていることを確認してください 3:「Sphere Prefab」から「Sphere」を選択してください ![image](https://hackmd.io/_uploads/HkMoNwnqC.png) </details> 結果: 球が衝突しても、 ![image](https://hackmd.io/_uploads/rJupuwncA.png) 変な方向にいっても、 ![image](https://hackmd.io/_uploads/SJzMFPh9R.png) 次の球が出てきます! ![image](https://hackmd.io/_uploads/HyeWcuv3q0.png) </details> <details><summary>4.タイトル画面作成</summary> 基本的にここのサイトの通りにやるとできる!(動画めちゃわかりやすい) ↓タイトル画面用のScene作成〜タイトル記入 https://yomeyome.hateblo.jp/entry/unity_titlescene ↓スタートボタン〜画面遷移 https://yomeyome.hateblo.jp/entry/unity_screen_transition#Unity%E3%81%A7%E3%82%BF%E3%82%A4%E3%83%88%E3%83%AB%E3%81%8B%E3%82%89%E3%82%B2%E3%83%BC%E3%83%A0%E7%94%BB%E9%9D%A2%E3%81%B8%E7%A7%BB%E5%8B%95%E3%81%95%E3%81%9B%E3%82%8B%E6%96%B9%E6%B3%95 <details><summary>完成(仮)</summary> タイトル画面(仮)をクリックすると。。。 ![image](https://hackmd.io/_uploads/HJFdti1ykl.png) ゲーム画面に遷移! ![image](https://hackmd.io/_uploads/HyJiFj11kl.png) </details> </details>

    Import from clipboard

    Paste your markdown or webpage here...

    Advanced permission required

    Your current role can only read. Ask the system administrator to acquire write and comment permission.

    This team is disabled

    Sorry, this team is disabled. You can't edit this note.

    This note is locked

    Sorry, only owner can edit this note.

    Reach the limit

    Sorry, you've reached the max length this note can be.
    Please reduce the content or divide it to more notes, thank you!

    Import from Gist

    Import from Snippet

    or

    Export to Snippet

    Are you sure?

    Do you really want to delete this note?
    All users will lose their connection.

    Create a note from template

    Create a note from template

    Oops...
    This template has been removed or transferred.
    Upgrade
    All
    • All
    • Team
    No template.

    Create a template

    Upgrade

    Delete template

    Do you really want to delete this template?
    Turn this template into a regular note and keep its content, versions, and comments.

    This page need refresh

    You have an incompatible client version.
    Refresh to update.
    New version available!
    See releases notes here
    Refresh to enjoy new features.
    Your user state has changed.
    Refresh to load new user state.

    Sign in

    Forgot password
    or
    Sign in via Facebook Sign in via X(Twitter) Sign in via GitHub Sign in via Dropbox Sign in with Wallet
    Wallet ( )
    Connect another wallet

    New to HackMD? Sign up

    By signing in, you agree to our terms of service.

    Help

    • English
    • 中文
    • Français
    • Deutsch
    • 日本語
    • Español
    • Català
    • Ελληνικά
    • Português
    • italiano
    • Türkçe
    • Русский
    • Nederlands
    • hrvatski jezik
    • język polski
    • Українська
    • हिन्दी
    • svenska
    • Esperanto
    • dansk

    Documents

    Help & Tutorial

    How to use Book mode

    Slide Example

    API Docs

    Edit in VSCode

    Install browser extension

    Contacts

    Feedback

    Discord

    Send us email

    Resources

    Releases

    Pricing

    Blog

    Policy

    Terms

    Privacy

    Cheatsheet

    Syntax Example Reference
    # Header Header 基本排版
    - Unordered List
    • Unordered List
    1. Ordered List
    1. Ordered List
    - [ ] Todo List
    • Todo List
    > Blockquote
    Blockquote
    **Bold font** Bold font
    *Italics font* Italics font
    ~~Strikethrough~~ Strikethrough
    19^th^ 19th
    H~2~O H2O
    ++Inserted text++ Inserted text
    ==Marked text== Marked text
    [link text](https:// "title") Link
    ![image alt](https:// "title") Image
    `Code` Code 在筆記中貼入程式碼
    ```javascript
    var i = 0;
    ```
    var i = 0;
    :smile: :smile: Emoji list
    {%youtube youtube_id %} Externals
    $L^aT_eX$ LaTeX
    :::info
    This is a alert area.
    :::

    This is a alert area.

    Versions and GitHub Sync
    Get Full History Access

    • Edit version name
    • Delete

    revision author avatar     named on  

    More Less

    Note content is identical to the latest version.
    Compare
      Choose a version
      No search result
      Version not found
    Sign in to link this note to GitHub
    Learn more
    This note is not linked with GitHub
     

    Feedback

    Submission failed, please try again

    Thanks for your support.

    On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

    Please give us some advice and help us improve HackMD.

     

    Thanks for your feedback

    Remove version name

    Do you want to remove this version name and description?

    Transfer ownership

    Transfer to
      Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

        Link with GitHub

        Please authorize HackMD on GitHub
        • Please sign in to GitHub and install the HackMD app on your GitHub repo.
        • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
        Learn more  Sign in to GitHub

        Push the note to GitHub Push to GitHub Pull a file from GitHub

          Authorize again
         

        Choose which file to push to

        Select repo
        Refresh Authorize more repos
        Select branch
        Select file
        Select branch
        Choose version(s) to push
        • Save a new version and push
        • Choose from existing versions
        Include title and tags
        Available push count

        Pull from GitHub

         
        File from GitHub
        File from HackMD

        GitHub Link Settings

        File linked

        Linked by
        File path
        Last synced branch
        Available push count

        Danger Zone

        Unlink
        You will no longer receive notification when GitHub file changes after unlink.

        Syncing

        Push failed

        Push successfully