<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>基本操作 アーカイブ - だくまたゲーム制作ブログ</title>
	<atom:link href="https://d9m.one/category/unity/proc/feed/" rel="self" type="application/rss+xml" />
	<link>https://d9m.one/category/unity/proc/</link>
	<description></description>
	<lastBuildDate>Wed, 07 Sep 2022 13:27:25 +0000</lastBuildDate>
	<language>ja</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	
	<item>
		<title>【基本操作】タマあんどヒシガタ～３／３　ゲーム仕上げ【パズル】</title>
		<link>https://d9m.one/proc_tandh3/</link>
					<comments>https://d9m.one/proc_tandh3/#respond</comments>
		
		<dc:creator><![CDATA[だくまた]]></dc:creator>
		<pubDate>Fri, 22 Jul 2022 09:36:54 +0000</pubDate>
				<category><![CDATA[Unity]]></category>
		<category><![CDATA[基本操作]]></category>
		<category><![CDATA[自作ゲーム]]></category>
		<category><![CDATA[チュートリアル]]></category>
		<guid isPermaLink="false">https://d9m.one/?p=958</guid>

					<description><![CDATA[<p>●ステージ作成 ▷カメラ設定 ステージを見渡せるようカメラの姿勢を調整します。 ・位置、回転、スケール設定 ヒエラルキーの「Main Camera」をクリック インスペクターのTransformにある位置を(4.5, 1 [&#8230;]</p>
<p>投稿 <a href="https://d9m.one/proc_tandh3/">【基本操作】タマあんどヒシガタ～３／３　ゲーム仕上げ【パズル】</a> は <a href="https://d9m.one">だくまたゲーム制作ブログ</a> に最初に表示されました。</p>
]]></description>
										<content:encoded><![CDATA[
<h3 class="has-background has-medium-font-size wp-block-heading" style="background-color:#e5f7fd"><span id="toc1">●ステージ作成</span></h3>



<div style="height:16px" aria-hidden="true" class="wp-block-spacer"></div>



<div class="wp-block-group is-layout-flow wp-block-group-is-layout-flow">
<h4 class="wp-block-heading"><span id="toc2">▷カメラ設定</span></h4>



<div class="wp-block-group is-layout-flow wp-block-group-is-layout-flow">
<p>ステージを見渡せるようカメラの姿勢を調整します。</p>



<figure class="wp-block-image size-full is-resized"><a href="https://d9m.one/wp-content/uploads/2022/07/TandH_026.png"><img fetchpriority="high" decoding="async" src="https://d9m.one/wp-content/uploads/2022/07/TandH_026.png" alt="" class="wp-image-846" width="658" height="475"/></a><figcaption>カメラ設定</figcaption></figure>



<p class="has-medium-font-size"><strong>・位置、回転、スケール設定</strong></p>



<ol class="wp-block-list"><li>ヒエラルキーの「Main Camera」をクリック</li><li>インスペクターのTransformにある位置を(4.5, 16, -2)とする</li><li>インスペクターのTransformにある回転を(65, 0, 0)とする</li><li>インスペクターのTransformにあるスケールを(1, 1, 1)とする</li></ol>



<p class="has-medium-font-size"><strong>・アスペクト比設定</strong></p>



<ol class="wp-block-list"><li>ゲームビュー上メニュー左から３番目ドロップダウンをクリック</li><li>「9:16 Aspect」をクリック、無い場合は以降を操作</li><li>左下の「＋」をクリック</li><li>ドロップダウン「タイプ」をクリックし、「アスペクト比」をクリック</li><li>幅＆高さの「X」に(9)、「Y」に(16)を入力</li><li>「OK」をクリック</li></ol>
</div>



<h4 class="wp-block-heading"><span id="toc3">▷プレハブ化</span></h4>



<div class="wp-block-group is-layout-flow wp-block-group-is-layout-flow">
<p>ステージに２つ以上配置するオブジェクトをプレハブ化し、量産化しやすくします。<br>対象はトゲ、壁、ジャンプ台の３つです。</p>



<figure class="wp-block-image size-full is-resized"><a href="https://d9m.one/wp-content/uploads/2022/07/TandH_027.png"><img decoding="async" src="https://d9m.one/wp-content/uploads/2022/07/TandH_027.png" alt="" class="wp-image-848" width="658" height="475" srcset="https://d9m.one/wp-content/uploads/2022/07/TandH_027.png 877w, https://d9m.one/wp-content/uploads/2022/07/TandH_027-300x217.png 300w, https://d9m.one/wp-content/uploads/2022/07/TandH_027-768x554.png 768w" sizes="(max-width: 658px) 100vw, 658px" /></a><figcaption>プレハブ化</figcaption></figure>



<p class="has-medium-font-size"><strong>・プレハブ化</strong></p>



<ol class="wp-block-list"><li>ヒエラルキーの「Toge」をプロジェクトの「Assets」にドラッグ＆ドロップ</li><li>ヒエラルキーの「Block」をプロジェクトの「Assets」にドラッグ＆ドロップ</li><li>ヒエラルキーの「Jump」をプロジェクトの「Assets」にドラッグ＆ドロップ</li></ol>
</div>



<h4 class="wp-block-heading"><span id="toc4">▷単一オブジェクト配置</span></h4>



<div class="wp-block-group is-layout-flow wp-block-group-is-layout-flow">
<p>タマ、ヒシガタ、ゴールの位置を設定します。</p>



<figure class="wp-block-image size-full is-resized"><a href="https://d9m.one/wp-content/uploads/2022/07/TandH_028.png"><img decoding="async" src="https://d9m.one/wp-content/uploads/2022/07/TandH_028.png" alt="" class="wp-image-849" width="658" height="475" srcset="https://d9m.one/wp-content/uploads/2022/07/TandH_028.png 877w, https://d9m.one/wp-content/uploads/2022/07/TandH_028-300x217.png 300w, https://d9m.one/wp-content/uploads/2022/07/TandH_028-768x554.png 768w" sizes="(max-width: 658px) 100vw, 658px" /></a><figcaption>単一オブジェクト配置</figcaption></figure>



<p class="has-medium-font-size"><strong>・位置設定</strong></p>



<ol class="wp-block-list"><li>ヒエラルキーの「Tama」をクリック</li><li>インスペクターのTransformにある位置を(1, 0, 8)とする</li><li>ヒエラルキーの「Hisi」をクリック</li><li>インスペクターのTransformにある位置を(8, 0, 1)とする</li><li>ヒエラルキーの「Goal」をクリック</li><li>インスペクターのTransformにある位置を(7, 0, 4)とする</li></ol>
</div>



<h4 class="wp-block-heading"><span id="toc5">▷トゲ配置</span></h4>



<div class="wp-block-group is-layout-flow wp-block-group-is-layout-flow">
<p>トゲ配置用の空オブジェクトにトゲを格納し、複製しながら配置していきます。</p>



<figure class="wp-block-image size-full is-resized"><a href="https://d9m.one/wp-content/uploads/2022/07/TandH_029.png"><img decoding="async" src="https://d9m.one/wp-content/uploads/2022/07/TandH_029.png" alt="" class="wp-image-851" width="658" height="475" srcset="https://d9m.one/wp-content/uploads/2022/07/TandH_029.png 877w, https://d9m.one/wp-content/uploads/2022/07/TandH_029-300x217.png 300w, https://d9m.one/wp-content/uploads/2022/07/TandH_029-768x554.png 768w" sizes="(max-width: 658px) 100vw, 658px" /></a><figcaption>トゲ配置</figcaption></figure>



<p class="has-medium-font-size"><strong>・空オブジェクト作成</strong></p>



<ol class="wp-block-list"><li>ヒエラルキー左上の「＋」をクリック</li><li>「空のオブジェクトを作成」をクリック</li><li>「Toges」と入力し、ENTERキーを押す</li></ol>



<p class="has-medium-font-size"><strong>・位置スケールリセット</strong></p>



<ol class="wp-block-list"><li>インスペクターのTransformにある縦の三点リーダーをクリック</li><li>リセットをクリック</li></ol>



<p class="has-medium-font-size"><strong>・階層設定</strong></p>



<ol class="wp-block-list"><li>ヒエラルキーの「Toge」をヒエラルキーの「Toges」にドラッグ＆ドロップ</li></ol>



<p class="has-medium-font-size"><strong>・位置設定</strong></p>



<ol class="wp-block-list"><li>インスペクターのTransformにある位置を(1, 0, 0)とする</li></ol>



<p class="has-medium-font-size"><strong>・複製、位置設定</strong></p>



<ol class="wp-block-list"><li>ヒエラルキーの「Toges&gt;Toge」をクリック</li><li>CTRLを押しながらDキーを押す</li><li>インスペクターのTransformにある位置を(9, 0, 1)とする</li><li>ヒエラルキーの「Toges&gt;Toge (1)」をクリック</li><li>CTRLを押しながらDキーを押す</li><li>インスペクターのTransformにある位置を(8, 0, 9)とする</li><li>ヒエラルキーの「Toges&gt;Toge (2)」をクリック</li><li>CTRLを押しながらDキーを押す</li><li>インスペクターのTransformにある位置を(0, 0, 8)とする</li><li>ヒエラルキーの「Toges&gt;Toge (3)」をクリック</li><li>CTRLを押しながらDキーを押す</li><li>インスペクターのTransformにある位置を(5, 0, 4)とする</li><li>ヒエラルキーの「Toges&gt;Toge (4)」をクリック</li><li>CTRLを押しながらDキーを押す</li><li>インスペクターのTransformにある位置を(6, 0, 2)とする</li><li>ヒエラルキーの「Toges&gt;Toge (5)」をクリック</li><li>CTRLを押しながらDキーを押す</li><li>インスペクターのTransformにある位置を(5, 0, 2)とする</li><li>ヒエラルキーの「Toges&gt;Toge (6)」をクリック</li><li>CTRLを押しながらDキーを押す</li><li>インスペクターのTransformにある位置を(4, 0, 2)とする</li></ol>



<p class="has-medium-font-size"><strong>・階層を閉じる</strong></p>



<ol class="wp-block-list"><li>ヒエラルキーの「Toges」左にある「▼」をクリック</li></ol>
</div>



<h4 class="wp-block-heading"><span id="toc6">▷ジャンプ台配置</span></h4>



<div class="wp-block-group is-layout-flow wp-block-group-is-layout-flow">
<p>ジャンプ台配置用の空オブジェクトにジャンプ台を格納し、複製しながら配置していきます。</p>



<figure class="wp-block-image size-full is-resized"><a href="https://d9m.one/wp-content/uploads/2022/07/TandH_030.png"><img decoding="async" src="https://d9m.one/wp-content/uploads/2022/07/TandH_030.png" alt="" class="wp-image-852" width="658" height="475" srcset="https://d9m.one/wp-content/uploads/2022/07/TandH_030.png 877w, https://d9m.one/wp-content/uploads/2022/07/TandH_030-300x217.png 300w, https://d9m.one/wp-content/uploads/2022/07/TandH_030-768x554.png 768w" sizes="(max-width: 658px) 100vw, 658px" /></a><figcaption>ジャンプ台配置</figcaption></figure>



<p class="has-medium-font-size"><strong>・空オブジェクト作成</strong></p>



<ol class="wp-block-list"><li>ヒエラルキー左上の「＋」をクリック</li><li>「空のオブジェクトを作成」をクリック</li><li>「Jumps」と入力し、ENTERキーを押す</li></ol>



<p class="has-medium-font-size"><strong>・位置スケールリセット</strong></p>



<ol class="wp-block-list"><li>インスペクターのTransformにある縦の三点リーダーをクリック</li><li>リセットをクリック</li></ol>



<p class="has-medium-font-size"><strong>・階層設定</strong></p>



<ol class="wp-block-list"><li>ヒエラルキーの「Jump」をヒエラルキーの「Jumps」にドラッグ＆ドロップ</li></ol>



<p class="has-medium-font-size"><strong>・位置設定</strong></p>



<ol class="wp-block-list"><li>インスペクターのTransformにある位置を(1, 0, 9)とする</li></ol>



<p class="has-medium-font-size"><strong>・複製、位置設定</strong></p>



<ol class="wp-block-list"><li>ヒエラルキーの「Jumps&gt;Jump」をクリック</li><li>CTRLを押しながらDキーを押す</li><li>インスペクターのTransformにある位置を(0, 0, 1)とする</li><li>ヒエラルキーの「Jumps&gt;Jump (1)」をクリック</li><li>CTRLを押しながらDキーを押す</li><li>インスペクターのTransformにある位置を(8, 0, 0)とする</li><li>ヒエラルキーの「Jumps&gt;Jump (2)」をクリック</li><li>CTRLを押しながらDキーを押す</li><li>インスペクターのTransformにある位置を(9, 0, 8)とする</li><li>ヒエラルキーの「Jumps&gt;Jump (3)」をクリック</li><li>CTRLを押しながらDキーを押す</li><li>インスペクターのTransformにある位置を(6, 0, 9)とする</li><li>ヒエラルキーの「Jumps&gt;Jump (4)」をクリック</li><li>CTRLを押しながらDキーを押す</li><li>インスペクターのTransformにある位置を(5, 0, 9)とする</li><li>ヒエラルキーの「Jumps&gt;Jump (5)」をクリック</li><li>CTRLを押しながらDキーを押す</li><li>インスペクターのTransformにある位置を(4, 0, 9)とする</li><li>ヒエラルキーの「Jumps&gt;Jump (6)」をクリック</li><li>CTRLを押しながらDキーを押す</li><li>インスペクターのTransformにある位置を(3, 0, 4)とする</li></ol>



<p class="has-medium-font-size"><strong>・階層を閉じる</strong></p>



<ol class="wp-block-list"><li>ヒエラルキーの「Jumps」左にある「▼」をクリック</li></ol>
</div>



<h4 class="wp-block-heading"><span id="toc7">▷壁配置</span></h4>



<div class="wp-block-group is-layout-flow wp-block-group-is-layout-flow">
<p>壁配置用の空オブジェクトに壁を格納し、複製しながら配置していきます。</p>



<figure class="wp-block-image size-full is-resized"><a href="https://d9m.one/wp-content/uploads/2022/07/TandH_031.png"><img decoding="async" src="https://d9m.one/wp-content/uploads/2022/07/TandH_031.png" alt="" class="wp-image-854" width="658" height="475" srcset="https://d9m.one/wp-content/uploads/2022/07/TandH_031.png 877w, https://d9m.one/wp-content/uploads/2022/07/TandH_031-300x217.png 300w, https://d9m.one/wp-content/uploads/2022/07/TandH_031-768x554.png 768w" sizes="(max-width: 658px) 100vw, 658px" /></a><figcaption>壁配置</figcaption></figure>



<p class="has-medium-font-size"><strong>・空オブジェクト作成</strong></p>



<ol class="wp-block-list"><li>ヒエラルキー左上の「＋」をクリック</li><li>「空のオブジェクトを作成」をクリック</li><li>「Blocks」と入力し、ENTERキーを押す</li></ol>



<p class="has-medium-font-size"><strong>・位置スケールリセット</strong></p>



<ol class="wp-block-list"><li>インスペクターのTransformにある縦の三点リーダーをクリック</li><li>リセットをクリック</li></ol>



<p class="has-medium-font-size"><strong>・階層設定</strong></p>



<ol class="wp-block-list"><li>ヒエラルキーの「Block」をヒエラルキーの「Blocks」にドラッグ＆ドロップ</li></ol>



<p class="has-medium-font-size"><strong>・位置設定</strong></p>



<ol class="wp-block-list"><li>インスペクターのTransformにある位置を(0, 0, 9)とする</li></ol>



<p class="has-medium-font-size"><strong>・複製、位置設定</strong></p>



<ol class="wp-block-list"><li>ヒエラルキーの「Blocks&gt;Block」をクリック</li><li>CTRLを押しながらDキーを押す</li><li>インスペクターのTransformにある位置を(0, 0, 7)とする</li><li>ヒエラルキーの「Blocks&gt;Block (1)」をクリック</li><li>CTRLを押しながらDキーを押す</li><li>インスペクターのTransformにある位置を(0, 0, 6)とする</li><li>ヒエラルキーの「Blocks&gt;Block (2)」をクリック</li><li>CTRLを押しながらDキーを押す</li><li>インスペクターのTransformにある位置を(0, 0, 5)とする</li><li>ヒエラルキーの「Blocks&gt;Block (3)」をクリック</li><li>CTRLを押しながらDキーを押す</li><li>インスペクターのTransformにある位置を(0, 0, 4)とする</li><li>ヒエラルキーの「Blocks&gt;Block (4)」をクリック</li><li>CTRLを押しながらDキーを押す</li><li>インスペクターのTransformにある位置を(0, 0, 3)とする</li><li>ヒエラルキーの「Blocks&gt;Block (5)」をクリック</li><li>CTRLを押しながらDキーを押す</li><li>インスペクターのTransformにある位置を(0, 0, 2)とする</li><li>ヒエラルキーの「Blocks&gt;Block (6)」をクリック</li><li>CTRLを押しながらDキーを押す</li><li>インスペクターのTransformにある位置を(0, 0, 0)とする</li></ol>



<ol class="wp-block-list"><li>ヒエラルキーの「Blocks&gt;Block (7)」をクリック</li><li>CTRLを押しながらDキーを押す</li><li>インスペクターのTransformにある位置を(2, 0, 0)とする</li><li>ヒエラルキーの「Blocks&gt;Block (8)」をクリック</li><li>CTRLを押しながらDキーを押す</li><li>インスペクターのTransformにある位置を(3, 0, 0)とする</li><li>ヒエラルキーの「Blocks&gt;Block (9)」をクリック</li><li>CTRLを押しながらDキーを押す</li><li>インスペクターのTransformにある位置を(4, 0, 0)とする</li><li>ヒエラルキーの「Blocks&gt;Block (10)」をクリック</li><li>CTRLを押しながらDキーを押す</li><li>インスペクターのTransformにある位置を(5, 0, 0)とする</li><li>ヒエラルキーの「Blocks&gt;Block (11)」をクリック</li><li>CTRLを押しながらDキーを押す</li><li>インスペクターのTransformにある位置を(6, 0, 0)とする</li><li>ヒエラルキーの「Blocks&gt;Block (12)」をクリック</li><li>CTRLを押しながらDキーを押す</li><li>インスペクターのTransformにある位置を(7, 0, 0)とする</li><li>ヒエラルキーの「Blocks&gt;Block (13)」をクリック</li><li>CTRLを押しながらDキーを押す</li><li>インスペクターのTransformにある位置を(9, 0, 0)とする</li></ol>



<ol class="wp-block-list"><li>ヒエラルキーの「Blocks&gt;Block (14)」をクリック</li><li>CTRLを押しながらDキーを押す</li><li>インスペクターのTransformにある位置を(9, 0, 2)とする</li><li>ヒエラルキーの「Blocks&gt;Block (15)」をクリック</li><li>CTRLを押しながらDキーを押す</li><li>インスペクターのTransformにある位置を(9, 0, 3)とする</li><li>ヒエラルキーの「Blocks&gt;Block (16)」をクリック</li><li>CTRLを押しながらDキーを押す</li><li>インスペクターのTransformにある位置を(9, 0, 4)とする</li><li>ヒエラルキーの「Blocks&gt;Block (17)」をクリック</li><li>CTRLを押しながらDキーを押す</li><li>インスペクターのTransformにある位置を(9, 0, 5)とする</li><li>ヒエラルキーの「Blocks&gt;Block (18)」をクリック</li><li>CTRLを押しながらDキーを押す</li><li>インスペクターのTransformにある位置を(9, 0, 6)とする</li><li>ヒエラルキーの「Blocks&gt;Block (19)」をクリック</li><li>CTRLを押しながらDキーを押す</li><li>インスペクターのTransformにある位置を(9, 0, 7)とする</li><li>ヒエラルキーの「Blocks&gt;Block (20)」をクリック</li><li>CTRLを押しながらDキーを押す</li><li>インスペクターのTransformにある位置を(9, 0, 9)とする</li></ol>



<ol class="wp-block-list"><li>ヒエラルキーの「Blocks&gt;Block (21)」をクリック</li><li>CTRLを押しながらDキーを押す</li><li>インスペクターのTransformにある位置を(7, 0, 9)とする</li><li>ヒエラルキーの「Blocks&gt;Block (22)」をクリック</li><li>CTRLを押しながらDキーを押す</li><li>インスペクターのTransformにある位置を(3, 0, 9)とする</li><li>ヒエラルキーの「Blocks&gt;Block (23)」をクリック</li><li>CTRLを押しながらDキーを押す</li><li>インスペクターのTransformにある位置を(2, 0, 9)とする</li></ol>



<p class="has-medium-font-size"><strong>・階層を閉じる</strong></p>



<ol class="wp-block-list"><li>ヒエラルキーの「Blocks」左にある「▼」をクリック</li></ol>



<p class="has-medium-font-size"><strong>・プロジェクト保存</strong></p>



<ol class="wp-block-list"><li>CTRLを押しながらSキーを押す</li></ol>
</div>
</div>



<div style="height:16px" aria-hidden="true" class="wp-block-spacer"></div>



<h3 class="has-background has-medium-font-size wp-block-heading" style="background-color:#e5f7fd"><span id="toc8">●ミスUI作成</span></h3>



<div style="height:16px" aria-hidden="true" class="wp-block-spacer"></div>



<div class="wp-block-group is-layout-flow wp-block-group-is-layout-flow">
<h4 class="wp-block-heading"><span id="toc9">▷ミスUI作成</span></h4>



<div class="wp-block-group is-layout-flow wp-block-group-is-layout-flow">
<p>タマがトゲ、もしくはヒシガタに衝突した時に「Miss!」というテキストを表示します。</p>



<figure class="wp-block-image size-full is-resized"><a href="https://d9m.one/wp-content/uploads/2022/07/TandH_032.png"><img decoding="async" src="https://d9m.one/wp-content/uploads/2022/07/TandH_032.png" alt="" class="wp-image-855" width="658" height="475" srcset="https://d9m.one/wp-content/uploads/2022/07/TandH_032.png 877w, https://d9m.one/wp-content/uploads/2022/07/TandH_032-300x217.png 300w, https://d9m.one/wp-content/uploads/2022/07/TandH_032-768x554.png 768w" sizes="(max-width: 658px) 100vw, 658px" /></a><figcaption>ミスUI作成（画像はオブジェクト無効化前）</figcaption></figure>



<p class="has-medium-font-size"><strong>・テキスト作成</strong></p>



<ol class="wp-block-list"><li>ヒエラルキー左上の「＋」をクリック</li><li>「UI＞テキスト &#8211; TextMeshPro」をクリック</li><li>「TextMiss」と入力し、ENTERキーを押す</li></ol>



<p class="has-medium-font-size"><strong>・TextMeshPro</strong>準備</p>



<ol class="wp-block-list"><li>TMP Importerの「Import TMP Essentials」をクリック</li><li>TMP Importerの右上にある「×」をクリック</li></ol>



<p class="has-medium-font-size"><strong>・UI位置設定</strong></p>



<ol class="wp-block-list"><li>インスペクターのRectTransform左上にあるアイコンをクリック</li><li>アンカープリセットの右下にある「Stretch &#8211; Stretch」をダブルクリック</li><li>インスペクターのRectTransform右上にある上下左右を全て「0」に設定</li></ol>



<p class="has-medium-font-size"><strong>・表示文字設定</strong></p>



<ol class="wp-block-list"><li>インスペクターのTextMeshProにある「Text Input&gt;テキスト入力」を「Miss!」に設定</li></ol>



<p class="has-medium-font-size"><strong>・文字装飾</strong></p>



<ol class="wp-block-list"><li>インスペクターのTextMeshProにある「Main Settings&gt;Font Style」にある「B」をクリック</li><li>インスペクターのTextMeshProにある「Main Settings&gt;Audo Size」のチェックボックスをクリック</li><li>インスペクターのTextMeshProにある「Main Settings&gt;Vertex Color」右のカラーバーをクリックし、色ダイアログの16進数を「FF0000」に設定</li><li>色ダイアログの右上にある「×」をクリック</li><li>インスペクターの「Shader&gt;Outline」左にあるチェックボックスをクリック</li><li>インスペクターの「Shader&gt;Outline」にある「Thickness」を「0.2」に設定</li></ol>



<p class="has-medium-font-size"><strong>・オブジェクト無効化</strong></p>



<ol class="wp-block-list"><li>インスペクター上部の左上にあるチェックボックスをクリック</li></ol>
</div>



<h4 class="wp-block-heading"><span id="toc10">▷ミス制御</span></h4>



<p>タマがトゲ、もしくはヒシガタとぶつかった時にミステキストを表示するようにCharCtrlを修正します。</p>



<figure class="wp-block-image size-full is-resized"><a href="https://d9m.one/wp-content/uploads/2022/07/TandH_033.png"><img decoding="async" src="https://d9m.one/wp-content/uploads/2022/07/TandH_033.png" alt="" class="wp-image-857" width="658" height="475" srcset="https://d9m.one/wp-content/uploads/2022/07/TandH_033.png 877w, https://d9m.one/wp-content/uploads/2022/07/TandH_033-300x217.png 300w, https://d9m.one/wp-content/uploads/2022/07/TandH_033-768x554.png 768w" sizes="(max-width: 658px) 100vw, 658px" /></a><figcaption>ミス制御</figcaption></figure>



<div class="wp-block-group is-layout-flow wp-block-group-is-layout-flow">
<p class="has-medium-font-size"><strong>・スクリプト編集開始</strong></p>



<ol class="wp-block-list"><li>プロジェクトの「Assets&gt;CharCtrl」をダブルクリック</li></ol>



<p class="has-medium-font-size"><strong>・スクリプト変数定義</strong></p>



<ol class="wp-block-list"><li>クラス定義内の先頭に以下の変数を追加</li></ol>



<div class="hcb_wrap"><pre class="prism line-numbers lang-csharp" data-file="CharCtrl.cs" data-lang="C#"><code>    public GameObject TextMiss;         // ミスUI
</code></pre></div>



<p class="has-medium-font-size"><strong>・スクリプト関数修正</strong></p>



<ol class="wp-block-list"><li>「タマとヒシガタの位置が同じだった場合」の条件内にある「タマとヒシガタを削除」前に「ミスUIを有効化」する以下の処理を追加</li></ol>



<div class="hcb_wrap"><pre class="prism line-numbers lang-csharp" data-file="CharCtrl.cs" data-lang="C#"><code>                // ミスUIを有効化
                TextMiss.SetActive(true);
</code></pre></div>



<p class="has-medium-font-size"><strong>・スクリプト関数修正</strong></p>



<ol class="wp-block-list"><li>「トゲと重なったら自分とトゲを削除」の条件内の先頭に「自分がタマだった場合、ミスUIを有効化」する処理を追加</li></ol>



<div class="hcb_wrap"><pre class="prism line-numbers lang-csharp" data-file="CharCtrl.cs" data-lang="C#"><code>            // 自分がタマだった場合、ミスUIを有効化
            if (tag == &quot;Player&quot;)
            {
                TextMiss.SetActive(true);
            }
</code></pre></div>



<p class="has-medium-font-size"><strong>・スクリプト保存</strong></p>



<ol class="wp-block-list"><li>CTRLを押しながらSキーを押す</li></ol>



<p class="has-medium-font-size"><strong>・Unityに戻ってスクリプトをビルド</strong></p>



<ol class="wp-block-list"><li>Unityエディタのタイトルをクリック</li></ol>



<p class="has-medium-font-size"><strong>・オブジェクト割り当て</strong></p>



<ol class="wp-block-list"><li>ヒエラルキーの「Tama」をクリック</li><li>ヒエラルキーの「Canvas&gt;TextMiss」をインスペクターの「Char Ctrl (スクリプト)&gt;Text Miss」右の参照ボックスにドラッグ＆ドロップ</li></ol>



<p class="has-medium-font-size"><strong>・プロジェクト保存</strong></p>



<ol class="wp-block-list"><li>CTRLを押しながらSキーを押す</li></ol>
</div>



<h4 class="wp-block-heading"><span id="toc11">▷動作確認</span></h4>



<div class="wp-block-group is-layout-flow wp-block-group-is-layout-flow">
<p>ミスした時にミステキストが表示されるかどうか、プレビューして確認します。</p>



<figure class="wp-block-image size-full is-resized"><a href="https://d9m.one/wp-content/uploads/2022/07/TandH_034.png"><img decoding="async" src="https://d9m.one/wp-content/uploads/2022/07/TandH_034.png" alt="" class="wp-image-859" width="658" height="475" srcset="https://d9m.one/wp-content/uploads/2022/07/TandH_034.png 877w, https://d9m.one/wp-content/uploads/2022/07/TandH_034-300x217.png 300w, https://d9m.one/wp-content/uploads/2022/07/TandH_034-768x554.png 768w" sizes="(max-width: 658px) 100vw, 658px" /></a><figcaption>動作確認</figcaption></figure>



<p class="has-medium-font-size"><strong>・プレビュー開始</strong></p>



<ol class="wp-block-list"><li>エディタ上中央の「▶」をクリック</li></ol>



<p class="has-medium-font-size"><strong>・動作確認</strong></p>



<ol class="wp-block-list"><li>ミスした時にミステキストが表示されるかどうか確認</li></ol>



<p class="has-medium-font-size"><strong>・プレビュー終了</strong></p>



<ol class="wp-block-list"><li>エディタ上中央の「▶」をクリック</li></ol>
</div>
</div>



<div style="height:16px" aria-hidden="true" class="wp-block-spacer"></div>



<h3 class="has-background has-medium-font-size wp-block-heading" style="background-color:#e5f7fd"><span id="toc12">●クリアUI作成</span></h3>



<div style="height:16px" aria-hidden="true" class="wp-block-spacer"></div>



<div class="wp-block-group is-layout-flow wp-block-group-is-layout-flow">
<h4 class="wp-block-heading"><span id="toc13">▷クリアUI作成</span></h4>



<div class="wp-block-group is-layout-flow wp-block-group-is-layout-flow">
<p>タマがゴールに衝突した時に「Clear!」というテキストを表示します。</p>



<figure class="wp-block-image size-full is-resized"><a href="https://d9m.one/wp-content/uploads/2022/07/TandH_035.png"><img decoding="async" src="https://d9m.one/wp-content/uploads/2022/07/TandH_035.png" alt="" class="wp-image-861" width="658" height="475" srcset="https://d9m.one/wp-content/uploads/2022/07/TandH_035.png 877w, https://d9m.one/wp-content/uploads/2022/07/TandH_035-300x217.png 300w, https://d9m.one/wp-content/uploads/2022/07/TandH_035-768x554.png 768w" sizes="(max-width: 658px) 100vw, 658px" /></a><figcaption>クリアUI作成（画像はオブジェクト無効化前）</figcaption></figure>



<p class="has-medium-font-size"><strong>・オブジェクト複製</strong></p>



<ol class="wp-block-list"><li>ヒエラルキーの「Canvas&gt;TextMiss」をクリック</li><li>CTRLを押しながらDキーを押す</li></ol>



<p class="has-medium-font-size"><strong>・オブジェクト名変更</strong></p>



<ol class="wp-block-list"><li>F2キーを押して「TextClear」と入力し、ENTERを押す</li></ol>



<p class="has-medium-font-size"><strong>・オブジェクト有効化</strong></p>



<ol class="wp-block-list"><li>インスペクター上部の左上にあるチェックボックスをクリック</li></ol>



<p class="has-medium-font-size"><strong><strong>・表示文字設定</strong></strong></p>



<ol class="wp-block-list"><li>インスペクターのTextMeshProにある「Text Input&gt;テキスト入力」を「Clear!」に設定</li></ol>



<p class="has-medium-font-size"><strong><strong>・文字装飾</strong></strong></p>



<ol class="wp-block-list"><li>インスペクターのTextMeshProにある「Main Settings&gt;Vertex Color」右のカラーバーをクリックし、色ダイアログの16進数を「00FFFF」に設定</li><li>色ダイアログの右上にある「×」をクリック</li></ol>



<p class="has-medium-font-size"><strong><strong><strong>・オブジェクト無効化</strong></strong></strong></p>



<ol class="wp-block-list"><li>インスペクター上部の左上にあるチェックボックスをクリック</li></ol>
</div>



<h4 class="wp-block-heading"><span id="toc14">▷クリア制御</span></h4>



<p>タマがゴールと衝突した時にクリアテキストを表示するようにCharCtrlを修正します。</p>



<figure class="wp-block-image size-full is-resized"><a href="https://d9m.one/wp-content/uploads/2022/07/TandH_036.png"><img decoding="async" src="https://d9m.one/wp-content/uploads/2022/07/TandH_036.png" alt="" class="wp-image-862" width="658" height="475" srcset="https://d9m.one/wp-content/uploads/2022/07/TandH_036.png 877w, https://d9m.one/wp-content/uploads/2022/07/TandH_036-300x217.png 300w, https://d9m.one/wp-content/uploads/2022/07/TandH_036-768x554.png 768w" sizes="(max-width: 658px) 100vw, 658px" /></a><figcaption>クリア制御</figcaption></figure>



<div class="wp-block-group is-layout-flow wp-block-group-is-layout-flow">
<p class="has-medium-font-size"><strong><strong><strong>・スクリプト編集開始</strong></strong></strong></p>



<ol class="wp-block-list"><li>プロジェクトの「Assets&gt;CharCtrl」をダブルクリック</li></ol>



<p class="has-medium-font-size"><strong><strong><strong>・スクリプト変数定義</strong></strong></strong></p>



<ol class="wp-block-list"><li>ミスUIの定義の後に以下の変数を追加</li></ol>



<div class="hcb_wrap"><pre class="prism line-numbers lang-csharp" data-file="CharCtrl.cs" data-lang="C#"><code>    public GameObject TextClear;        // クリアUI
</code></pre></div>



<p class="has-medium-font-size"><strong><strong><strong>・スクリプト関数修正</strong></strong></strong></p>



<ol class="wp-block-list"><li>「自分がタマで、かつゴールと重なった場合」の条件内処理の先頭に以下のスクリプトを追加</li></ol>



<div class="hcb_wrap"><pre class="prism line-numbers lang-csharp" data-file="CharCtrl.cs" data-lang="C#"><code>            // クリアUIを有効化
            TextClear.SetActive(true);
</code></pre></div>



<p class="has-medium-font-size"><strong><strong><strong><strong>・スクリプト保存</strong></strong></strong></strong></p>



<ol class="wp-block-list"><li>CTRLを押しながらSキーを押す</li></ol>



<p class="has-medium-font-size"><strong><strong><strong><strong><strong><strong>・Unityに戻ってスクリプトをビルド</strong></strong></strong></strong></strong></strong></p>



<ol class="wp-block-list"><li>Unityエディタのタイトルをクリック</li></ol>



<p class="has-medium-font-size"><strong><strong><strong><strong><strong><strong>・オブジェクト割り当て</strong></strong></strong></strong></strong></strong></p>



<ol class="wp-block-list"><li>ヒエラルキーの「Tama」をクリック</li><li>ヒエラルキーの「Canvas&gt;TextClear」をインスペクターの「Char Ctrl (スクリプト)&gt;Text Clear」右の参照ボックスにドラッグ＆ドロップ</li></ol>



<p class="has-medium-font-size"><strong><strong><strong><strong><strong>・プロジェクト保存</strong></strong></strong></strong></strong></p>



<ol class="wp-block-list"><li>CTRLを押しながらSキーを押す</li></ol>
</div>



<h4 class="wp-block-heading"><span id="toc15">▷動作確認</span></h4>



<div class="wp-block-group is-layout-flow wp-block-group-is-layout-flow">
<p>タマがゴールに衝突した時にクリアテキストが表示されるかどうか、プレビューして確認します。</p>



<figure class="wp-block-image size-full is-resized"><a href="https://d9m.one/wp-content/uploads/2022/07/TandH_037.png"><img decoding="async" src="https://d9m.one/wp-content/uploads/2022/07/TandH_037.png" alt="" class="wp-image-863" width="658" height="475" srcset="https://d9m.one/wp-content/uploads/2022/07/TandH_037.png 877w, https://d9m.one/wp-content/uploads/2022/07/TandH_037-300x217.png 300w, https://d9m.one/wp-content/uploads/2022/07/TandH_037-768x554.png 768w" sizes="(max-width: 658px) 100vw, 658px" /></a><figcaption>動作確認</figcaption></figure>



<p class="has-medium-font-size"><strong><strong><strong><strong><strong>・プレビュー開始</strong></strong></strong></strong></strong></p>



<ol class="wp-block-list"><li>エディタ上中央の「▶」をクリック</li></ol>



<p class="has-medium-font-size"><strong><strong><strong><strong><strong>・動作確認</strong></strong></strong></strong></strong></p>



<ol class="wp-block-list"><li>タマがゴールに衝突した時にクリアテキストが表示されるかどうか確認</li></ol>



<p class="has-medium-font-size"><strong>・プレビュー終了</strong></p>



<ol class="wp-block-list"><li>エディタ上中央の「▶」をクリック</li></ol>
</div>
</div>



<div style="height:16px" aria-hidden="true" class="wp-block-spacer"></div>



<p class="has-text-align-center" style="font-size:80px"><strong>完成！</strong></p>



<div style="height:16px" aria-hidden="true" class="wp-block-spacer"></div>



<p>作成手順を書いた記事です。</p>



<p>　　　<a href="https://d9m.one/proc_tandh/">→紹介</a><br>　　　<a href="https://d9m.one/proc_tandh1/">→１／３　キャラクター作成</a><br>　　　<a href="https://d9m.one/proc_tandh2/" type="post">→２／３　オブジェクト作成</a><br>今▷　<a href="https://d9m.one/proc_tandh3/">→３／３　ゲーム仕上げ</a></p>



<p><a href="https://d9m.one/proc_tandh_full/">完全手順</a><br>※紹介と１～３の手順を１ページにまとめています。<br>　読み込みに時間がかかるかも知れません。</p>
<p>投稿 <a href="https://d9m.one/proc_tandh3/">【基本操作】タマあんどヒシガタ～３／３　ゲーム仕上げ【パズル】</a> は <a href="https://d9m.one">だくまたゲーム制作ブログ</a> に最初に表示されました。</p>
]]></content:encoded>
					
					<wfw:commentRss>https://d9m.one/proc_tandh3/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>【基本操作】タマあんどヒシガタ～２／３　オブジェクト作成【パズル】</title>
		<link>https://d9m.one/proc_tandh2/</link>
					<comments>https://d9m.one/proc_tandh2/#respond</comments>
		
		<dc:creator><![CDATA[だくまた]]></dc:creator>
		<pubDate>Fri, 22 Jul 2022 09:35:28 +0000</pubDate>
				<category><![CDATA[Unity]]></category>
		<category><![CDATA[基本操作]]></category>
		<category><![CDATA[自作ゲーム]]></category>
		<category><![CDATA[チュートリアル]]></category>
		<guid isPermaLink="false">https://d9m.one/?p=954</guid>

					<description><![CDATA[<p>●床作成 タマやヒシガタが動き回る「地面」を作成します。 ▷床作成 平面を作成してTransformの位置を(4.5, -0.5, 4.5)とし、グレーのチェッカー模様に設定したマテリアルを割り当てます。 ・平面作成 ヒ [&#8230;]</p>
<p>投稿 <a href="https://d9m.one/proc_tandh2/">【基本操作】タマあんどヒシガタ～２／３　オブジェクト作成【パズル】</a> は <a href="https://d9m.one">だくまたゲーム制作ブログ</a> に最初に表示されました。</p>
]]></description>
										<content:encoded><![CDATA[
<div style="height:16px" aria-hidden="true" class="wp-block-spacer"></div>



<h3 class="has-background has-medium-font-size wp-block-heading" style="background-color:#e5f7fd"><span id="toc1">●床作成</span></h3>



<div class="wp-block-group is-layout-flow wp-block-group-is-layout-flow">
<div style="height:16px" aria-hidden="true" class="wp-block-spacer"></div>



<p>タマやヒシガタが動き回る「地面」を作成します。</p>



<h4 class="wp-block-heading"><span id="toc2">▷床作成</span></h4>



<div class="wp-block-group is-layout-flow wp-block-group-is-layout-flow">
<p>平面を作成してTransformの位置を(4.5, -0.5, 4.5)とし、グレーのチェッカー模様に設定したマテリアルを割り当てます。</p>



<figure class="wp-block-image size-full is-resized"><a href="https://d9m.one/wp-content/uploads/2022/07/TandH_013.png"><img decoding="async" src="https://d9m.one/wp-content/uploads/2022/07/TandH_013.png" alt="" class="wp-image-823" width="658" height="475" srcset="https://d9m.one/wp-content/uploads/2022/07/TandH_013.png 877w, https://d9m.one/wp-content/uploads/2022/07/TandH_013-300x217.png 300w, https://d9m.one/wp-content/uploads/2022/07/TandH_013-768x554.png 768w" sizes="(max-width: 658px) 100vw, 658px" /></a><figcaption>床作成</figcaption></figure>



<p class="has-medium-font-size"><strong>・平面作成</strong></p>



<ol class="wp-block-list"><li>ヒエラルキー左上の「＋」をクリック</li><li>「3Dオブジェクト＞平面」をクリック</li><li>「Floor」と入力し、ENTERキーを押す</li></ol>



<p class="has-medium-font-size"><strong>・位置設定</strong></p>



<ol class="wp-block-list"><li>インスペクターのTransformにある位置を(4.5, -0.5, 4.5)とする</li></ol>



<p class="has-medium-font-size"><strong>・マテリアル作成</strong></p>



<ol class="wp-block-list"><li>プロジェクトの「Assets」を右クリックし、「作成＞マテリアル」をクリック</li><li>「matFloor」と入力し、ENTERキーを押す</li></ol>



<p class="has-medium-font-size"><strong>・マテリアルテクスチャ設定</strong></p>



<ol class="wp-block-list"><li>インスペクターの「Main Maps&gt;アルベド」左の◎をクリックし、「Default-Checker-Gray」をダブルクリック</li></ol>



<p class="has-medium-font-size"><strong>・マテリアル色設定</strong></p>



<ol class="wp-block-list"><li>インスペクターの「Main Maps&gt;アルベド＞カラーバー」をクリックし、色ダイアログの16進数を「CCCCCC」に設定</li><li>色ダイアログの右上にある「×」をクリック</li></ol>



<p class="has-medium-font-size"><strong>・マテリアルタイリング設定</strong></p>



<ol class="wp-block-list"><li>インスペクターの「Main Maps&gt;タイリング」を(5, 5)に設定</li></ol>



<p class="has-medium-font-size"><strong>・マテリアル割り当て</strong></p>



<ol class="wp-block-list"><li>プロジェクトの「matFloor」をヒエラルキーの「Floor」にドラッグ＆ドロップ</li></ol>



<p class="has-medium-font-size"><strong><strong><strong>・プロジェクト保存</strong></strong></strong></p>



<ol class="wp-block-list"><li>CTRLを押しながらSキーを押す</li></ol>
</div>



<div style="height:16px" aria-hidden="true" class="wp-block-spacer"></div>
</div>



<h3 class="has-background has-medium-font-size wp-block-heading" style="background-color:#e5f7fd"><span id="toc3">●壁作成</span></h3>



<div class="wp-block-group is-layout-flow wp-block-group-is-layout-flow">
<div style="height:16px" aria-hidden="true" class="wp-block-spacer"></div>



<p>タマとヒシガタの移動を停止させる壁を作成します。<br>移動先に壁がある場合、推進力を失って停止します。</p>



<h4 class="wp-block-heading"><span id="toc4">▷壁作成</span></h4>



<div class="wp-block-group is-layout-flow wp-block-group-is-layout-flow">
<p>箱を作成してTransformの位置を(0, 0, 5)とし、オレンジ色の「Background」に設定したマテリアルを割り当てます。</p>



<figure class="wp-block-image size-full is-resized"><a href="https://d9m.one/wp-content/uploads/2022/07/TandH_014.png"><img decoding="async" src="https://d9m.one/wp-content/uploads/2022/07/TandH_014.png" alt="" class="wp-image-825" width="658" height="475" srcset="https://d9m.one/wp-content/uploads/2022/07/TandH_014.png 877w, https://d9m.one/wp-content/uploads/2022/07/TandH_014-300x217.png 300w, https://d9m.one/wp-content/uploads/2022/07/TandH_014-768x554.png 768w" sizes="(max-width: 658px) 100vw, 658px" /></a><figcaption>壁作成</figcaption></figure>



<p class="has-medium-font-size"><strong>・箱作成</strong></p>



<ol class="wp-block-list"><li>ヒエラルキー左上の「＋」をクリック</li><li>「3Dオブジェクト＞キューブ」をクリック</li><li>「Block」と入力し、ENTERキーを押す</li></ol>



<p class="has-medium-font-size">・<strong>位置、回転、スケール設定</strong></p>



<ol class="wp-block-list"><li>インスペクターのTransformにある位置を(0, 0, 5)とする</li><li>インスペクターのTransformにある回転を(0, 0, 0)とする</li><li>インスペクターのTransformにあるスケールを(1, 1, 1)とする</li></ol>



<p class="has-medium-font-size"><strong>・マテリアル作成</strong></p>



<ol class="wp-block-list"><li>プロジェクトの「Assets」を右クリックし、「作成＞マテリアル」をクリック</li><li>「matBlock」と入力し、ENTERキーを押す</li></ol>



<p class="has-medium-font-size"><strong>・マテリアルテクスチャ設定</strong></p>



<ol class="wp-block-list"><li>インスペクターの「Main Maps&gt;アルベド」左の◎をクリックし、「Background」をダブルクリック</li></ol>



<p class="has-medium-font-size"><strong>・マテリアル色設定</strong></p>



<ol class="wp-block-list"><li>インスペクターの「Main Maps&gt;アルベド＞カラーバー」をクリックし、色ダイアログの16進数を「FF8000」に設定</li><li>色ダイアログの右上にある「×」をクリック</li></ol>



<p class="has-medium-font-size"><strong>・マテリアル割り当て</strong></p>



<ol class="wp-block-list"><li>プロジェクトの「matBlock」をヒエラルキーの「Block」にドラッグ＆ドロップ</li></ol>
</div>



<h4 class="wp-block-heading"><span id="toc5">▷壁認識</span></h4>



<div class="wp-block-group is-layout-flow wp-block-group-is-layout-flow">
<p>タグ「Block」を作成し、壁に割り当てます。</p>



<figure class="wp-block-image size-full is-resized"><a href="https://d9m.one/wp-content/uploads/2022/07/TandH_015.png"><img decoding="async" src="https://d9m.one/wp-content/uploads/2022/07/TandH_015.png" alt="" class="wp-image-827" width="658" height="475" srcset="https://d9m.one/wp-content/uploads/2022/07/TandH_015.png 877w, https://d9m.one/wp-content/uploads/2022/07/TandH_015-300x217.png 300w, https://d9m.one/wp-content/uploads/2022/07/TandH_015-768x554.png 768w" sizes="(max-width: 658px) 100vw, 658px" /></a><figcaption>壁認識</figcaption></figure>



<p class="has-medium-font-size"><strong>・タグ作成</strong></p>



<ol class="wp-block-list"><li>ヒエラルキーの「Block」をクリック</li><li>インスペクター上部のタグドロップダウンをクリックし、「タグを追加&#8230;」をクリック</li><li>インスペクター「Tag &amp; Layers」にあるタグ欄右下の「＋」をクリック</li><li>「Block」と入力してENTERを押す</li></ol>



<p class="has-medium-font-size"><strong>・タグ割り当て</strong></p>



<ol class="wp-block-list"><li>ヒエラルキーの「Block」をクリック</li><li>インスペクターのタグドロップダウンをクリックし、「Block」をクリック</li></ol>
</div>



<h4 class="wp-block-heading"><span id="toc6">▷壁衝突</span></h4>



<div class="wp-block-group is-layout-flow wp-block-group-is-layout-flow">
<p>移動先に壁かジャンプ台があったら移動停止するようにCharCtrlを修正します。</p>



<figure class="wp-block-image size-full is-resized"><a href="https://d9m.one/wp-content/uploads/2022/07/TandH_016.png"><img decoding="async" src="https://d9m.one/wp-content/uploads/2022/07/TandH_016.png" alt="" class="wp-image-828" width="658" height="475" srcset="https://d9m.one/wp-content/uploads/2022/07/TandH_016.png 877w, https://d9m.one/wp-content/uploads/2022/07/TandH_016-300x217.png 300w, https://d9m.one/wp-content/uploads/2022/07/TandH_016-768x554.png 768w" sizes="(max-width: 658px) 100vw, 658px" /></a><figcaption>壁衝突</figcaption></figure>



<p class="has-medium-font-size">・<strong>スクリプト編集開始</strong></p>



<ol class="wp-block-list"><li>プロジェクトの「Assets&gt;CharCtrl」をダブルクリック</li></ol>



<p class="has-medium-font-size"><strong>・スクリプト関数修正</strong></p>



<ol class="wp-block-list"><li>FixedUpdate関数内の「経過フレーム数を0初期化する」の後に以下のスクリプトを追加</li></ol>



<div class="hcb_wrap"><pre class="prism line-numbers lang-csharp" data-file="CharCtrl.cs" data-lang="C#"><code>        // 移動先に壁かジャンプ台があったら移動終了
        GameObject moveObj = GetObject(transform.position + transform.forward);
        if (moveObj != null && (moveObj.tag == &quot;Block&quot; || moveObj.tag == &quot;Jump&quot;))
        {
            return;
        }
</code></pre></div>



<p class="has-medium-font-size"><strong>・スクリプト関数修正</strong></p>



<ol class="wp-block-list"><li>GetObject関数内の「処理対象とするタグの一覧を作成」を以下のスクリプトのように修正</li></ol>



<div class="hcb_wrap"><pre class="prism line-numbers lang-csharp" data-file="CharCtrl.cs" data-lang="C#"><code>        // 処理対象とするタグの一覧を作成
        string[] tags = new string[] { &quot;Toge&quot;, &quot;Block&quot; };
</code></pre></div>



<p class="has-medium-font-size"><strong>・スクリプト保存</strong></p>



<ol class="wp-block-list"><li>CTRLを押しながらSキーを押す</li></ol>



<p class="has-medium-font-size"><strong>・Unityに戻ってスクリプトをビルド</strong></p>



<ol class="wp-block-list"><li>Unityエディタのタイトルをクリック</li></ol>



<p class="has-medium-font-size"><strong>・プロジェクト保存</strong></p>



<ol class="wp-block-list"><li>CTRLを押しながらSキーを押す</li></ol>
</div>



<h4 class="wp-block-heading"><span id="toc7">▷動作確認</span></h4>



<div class="wp-block-group is-layout-flow wp-block-group-is-layout-flow">
<p>タマが壁に衝突したら止まるかどうか、プレビューして確認します。</p>



<figure class="wp-block-image size-full is-resized"><a href="https://d9m.one/wp-content/uploads/2022/07/TandH_017.png"><img decoding="async" src="https://d9m.one/wp-content/uploads/2022/07/TandH_017.png" alt="" class="wp-image-829" width="658" height="475" srcset="https://d9m.one/wp-content/uploads/2022/07/TandH_017.png 877w, https://d9m.one/wp-content/uploads/2022/07/TandH_017-300x217.png 300w, https://d9m.one/wp-content/uploads/2022/07/TandH_017-768x554.png 768w" sizes="(max-width: 658px) 100vw, 658px" /></a><figcaption>動作確認</figcaption></figure>



<p class="has-medium-font-size"><strong>・プレビュー開始</strong></p>



<ol class="wp-block-list"><li>エディタ上中央の「▶」をクリック</li></ol>



<p class="has-medium-font-size"><strong>・動作確認</strong></p>



<ol class="wp-block-list"><li>タマが壁に衝突したら止まることを確認</li></ol>



<p class="has-medium-font-size"><strong><strong>・プレビュー終了</strong></strong></p>



<ol class="has-medium-font-size wp-block-list"><li>エディタ上中央の「▶」をクリック</li></ol>
</div>



<div style="height:16px" aria-hidden="true" class="wp-block-spacer"></div>
</div>



<h3 class="has-background has-medium-font-size wp-block-heading" style="background-color:#e5f7fd"><span id="toc8">●ジャンプ台作成</span></h3>



<div style="height:16px" aria-hidden="true" class="wp-block-spacer"></div>



<div class="wp-block-group is-layout-flow wp-block-group-is-layout-flow">
<p>画面をクリックするとジャンプ台の隣にあるタマとヒシガタを押すようにして移動を開始させます。<br>また、壁と同じように移動先にジャンプ台があると移動を停止します。</p>



<h4 class="wp-block-heading"><span id="toc9">▷ジャンプ台作成</span></h4>



<div class="wp-block-group is-layout-flow wp-block-group-is-layout-flow">
<p>箱を作成してTransformの位置を(0, 0, -1)とし、緑色の「Knob」に設定したマテリアルを割り当てます。</p>



<figure class="wp-block-image size-full is-resized"><a href="https://d9m.one/wp-content/uploads/2022/07/TandH_018.png"><img decoding="async" src="https://d9m.one/wp-content/uploads/2022/07/TandH_018.png" alt="" class="wp-image-831" width="658" height="475" srcset="https://d9m.one/wp-content/uploads/2022/07/TandH_018.png 877w, https://d9m.one/wp-content/uploads/2022/07/TandH_018-300x217.png 300w, https://d9m.one/wp-content/uploads/2022/07/TandH_018-768x554.png 768w" sizes="(max-width: 658px) 100vw, 658px" /></a><figcaption>ジャンプ台作成</figcaption></figure>



<p class="has-medium-font-size"><strong>・箱作成</strong></p>



<ol class="wp-block-list"><li>ヒエラルキー左上の「＋」をクリック</li><li>「3Dオブジェクト＞キューブ」をクリック</li><li>「Jump」と入力し、ENTERキーを押す</li></ol>



<p class="has-medium-font-size"><strong>・<strong>位置、回転、スケール設定</strong></strong></p>



<ol class="wp-block-list"><li>インスペクターのTransformにある位置を(0, 0, -1)とする</li><li>インスペクターのTransformにある回転を(0, 0, 0)とする</li><li>インスペクターのTransformにあるスケールを(1, 1, 1)とする</li></ol>



<p class="has-medium-font-size"><strong><strong>・マテリアル作成</strong></strong></p>



<ol class="wp-block-list"><li>プロジェクトの「Assets」を右クリックし、「作成＞マテリアル」をクリック</li><li>「matJump」と入力し、ENTERキーを押す</li></ol>



<p class="has-medium-font-size"><strong><strong>・マテリアルテクスチャ設定</strong></strong></p>



<ol class="wp-block-list"><li>インスペクターの「Main Maps&gt;アルベド」左の◎をクリックし、「Knob」をダブルクリック</li></ol>



<p class="has-medium-font-size"><strong><strong>・マテリアル色設定</strong></strong></p>



<ol class="wp-block-list"><li>インスペクターの「Main Maps&gt;アルベド＞カラーバー」をクリックし、色ダイアログの16進数を「008000」に設定</li><li>色ダイアログの右上にある「×」をクリック</li></ol>



<p class="has-medium-font-size"><strong><strong>・マテリアル割り当て</strong></strong></p>



<ol class="wp-block-list"><li>プロジェクトの「matJump」をヒエラルキーの「Jump」にドラッグ＆ドロップ</li></ol>
</div>



<h4 class="wp-block-heading"><span id="toc10">▷ジャンプ台認識</span></h4>



<div class="wp-block-group is-layout-flow wp-block-group-is-layout-flow">
<p>タグ「Jump」を作成し、ジャンプ台に割り当てます。</p>



<figure class="wp-block-image size-full is-resized"><a href="https://d9m.one/wp-content/uploads/2022/07/TandH_019.png"><img decoding="async" src="https://d9m.one/wp-content/uploads/2022/07/TandH_019.png" alt="" class="wp-image-833" width="658" height="475" srcset="https://d9m.one/wp-content/uploads/2022/07/TandH_019.png 877w, https://d9m.one/wp-content/uploads/2022/07/TandH_019-300x217.png 300w, https://d9m.one/wp-content/uploads/2022/07/TandH_019-768x554.png 768w" sizes="(max-width: 658px) 100vw, 658px" /></a><figcaption>ジャンプ台認識</figcaption></figure>



<p class="has-medium-font-size"><strong>・タグ作成</strong></p>



<ol class="wp-block-list"><li>ヒエラルキーの「Jump」をクリック</li><li>インスペクターのタグドロップダウンをクリックし、「タグを追加&#8230;」をクリック</li><li>インスペクター「Tag &amp; Layers」にあるタグ欄右下の「＋」をクリック</li><li>「Jump」と入力してENTERを押す</li></ol>



<p class="has-medium-font-size"><strong>・タグ割り当て</strong></p>



<ol class="wp-block-list"><li>ヒエラルキーの「Jump」をクリック</li><li>インスペクターのタグドロップダウンをクリックし、「Jump」をクリック</li></ol>
</div>



<h4 class="wp-block-heading"><span id="toc11">▷ジャンプ台制御</span></h4>



<div class="wp-block-group is-layout-flow wp-block-group-is-layout-flow">
<p>ゲーム画面をクリックした時にタマかヒシガタが隣にあったら移動を開始するようCharCtrlを修正します。</p>



<figure class="wp-block-image size-full is-resized"><a href="https://d9m.one/wp-content/uploads/2022/07/TandH_020.png"><img decoding="async" src="https://d9m.one/wp-content/uploads/2022/07/TandH_020.png" alt="" class="wp-image-835" width="658" height="475" srcset="https://d9m.one/wp-content/uploads/2022/07/TandH_020.png 877w, https://d9m.one/wp-content/uploads/2022/07/TandH_020-300x217.png 300w, https://d9m.one/wp-content/uploads/2022/07/TandH_020-768x554.png 768w" sizes="(max-width: 658px) 100vw, 658px" /></a><figcaption>ジャンプ台制御</figcaption></figure>



<p class="has-medium-font-size"><strong>・スクリプト編集開始</strong></p>



<ol class="wp-block-list"><li>プロジェクトの「Assets&gt;CharCtrl」をダブルクリック</li></ol>



<p class="has-medium-font-size"><strong>・スクリプト変数追加</strong></p>



<ol class="wp-block-list"><li>「１歩に何フレームかけるか」の変数の前に以下の変数を追加</li></ol>



<div class="hcb_wrap"><pre class="prism line-numbers lang-plain"><code>    bool moveFlag = false;      // 移動中かどうか
</code></pre></div>



<p class="has-medium-font-size"><strong>・スクリプト関数修正</strong></p>



<ol class="wp-block-list"><li>Update関数内に以下のスクリプトを記述</li></ol>



<div class="hcb_wrap"><pre class="prism line-numbers lang-csharp" data-file="CharCtrl.cs" data-lang="C#"><code>        // マウスクリックされた場合
        if (Input.GetMouseButtonUp(0) == true)
        {
        }
</code></pre></div>



<p class="has-medium-font-size"><strong>・スクリプト関数修正</strong></p>



<ol class="wp-block-list"><li>Update関数内の「マウスクリックされた場合」の条件内に以下のスクリプトを記述</li></ol>



<div class="hcb_wrap"><pre class="prism line-numbers lang-csharp" data-file="CharCtrl.cs" data-lang="C#"><code>            // 現在の回転値を保存
            Quaternion rot = transform.rotation;
            // 上下左右のオブジェクトを取得
            transform.rotation = Quaternion.Euler(0, 0, 0);
            GameObject objU = GetObject(transform.position + transform.forward);
            GameObject objD = GetObject(transform.position - transform.forward);
            GameObject objL = GetObject(transform.position - transform.right);
            GameObject objR = GetObject(transform.position + transform.right);
</code></pre></div>



<p class="has-medium-font-size"><strong>・スクリプト関数修正</strong></p>



<ol class="wp-block-list"><li>Update関数内の「上下左右のオブジェクトを取得」処理の後に以下のスクリプトを記述</li></ol>



<div class="hcb_wrap"><pre class="prism line-numbers lang-csharp" data-file="CharCtrl.cs" data-lang="C#"><code>            // 指定方向がジャンプ台かつ逆側がなにも無いかトゲの場合、オブジェクトをジャンプ台の逆側に向ける
            float dir = -1;
            if (objU != null && objU.tag == &quot;Jump&quot; && (objD == null || objD.tag == &quot;Toge&quot;)) dir = 180;
            if (objD != null && objD.tag == &quot;Jump&quot; && (objU == null || objU.tag == &quot;Toge&quot;)) dir = 0;
            if (objL != null && objL.tag == &quot;Jump&quot; && (objR == null || objR.tag == &quot;Toge&quot;)) dir = 90;
            if (objR != null && objR.tag == &quot;Jump&quot; && (objL == null || objL.tag == &quot;Toge&quot;)) dir = 270;
            if (dir != -1)
            {
                moveFlag = true;
                rot = Quaternion.Euler(0, dir, 0);
            }
            // 回転値を設定
            transform.rotation = rot;
</code></pre></div>



<p class="has-medium-font-size"><strong>・スクリプト関数修正</strong></p>



<ol class="wp-block-list"><li>FixedUpdate関数内の「経過フレーム数を0初期化する」処理の後に以下のスクリプトを記述</li></ol>



<div class="hcb_wrap"><pre class="prism line-numbers lang-csharp" data-file="CharCtrl.cs" data-lang="C#"><code>        // 移動していない場合は終了
        if (moveFlag == false) return;
</code></pre></div>



<p class="has-medium-font-size"><strong>・スクリプト関数修正</strong></p>



<ol class="wp-block-list"><li>FixedUpdate関数内の「移動先に壁かジャンプ台があったら移動終了」条件内のreturn前に以下のスクリプトを記述</li></ol>



<div class="hcb_wrap"><pre class="prism line-numbers lang-csharp" data-file="CharCtrl.cs" data-lang="C#"><code>            moveFlag = false;
</code></pre></div>



<p class="has-medium-font-size"><strong>・スクリプト関数修正</strong></p>



<ol class="wp-block-list"><li>GetObject関数内の「処理対象とするタグの一覧を作成」を以下のスクリプトのように修正</li></ol>



<div class="hcb_wrap"><pre class="prism line-numbers lang-csharp" data-file="CharCtrl.cs" data-lang="C#"><code>        // 処理対象とするタグの一覧を作成
        string[] tags = new string[] { &quot;Toge&quot;, &quot;Block&quot;, &quot;Jump&quot; };
</code></pre></div>



<p class="has-medium-font-size"><strong>・スクリプト保存</strong></p>



<ol class="wp-block-list"><li>CTRLを押しながらSキーを押す</li></ol>



<p class="has-medium-font-size"><strong><strong>・Unityに戻ってスクリプトをビルド</strong></strong></p>



<ol class="wp-block-list"><li>Unityエディタのタイトルをクリック</li></ol>



<p class="has-medium-font-size"><strong>・プロジェクト保存</strong></p>



<ol class="wp-block-list"><li>CTRLを押しながらSキーを押す</li></ol>
</div>



<h4 class="wp-block-heading"><span id="toc12">▷動作確認</span></h4>



<div class="wp-block-group is-layout-flow wp-block-group-is-layout-flow">
<p>クリックしたらタマが動き出すかどうか、プレビューして確認します。</p>



<figure class="wp-block-image size-full is-resized"><a href="https://d9m.one/wp-content/uploads/2022/07/TandH_021.png"><img decoding="async" src="https://d9m.one/wp-content/uploads/2022/07/TandH_021.png" alt="" class="wp-image-837" width="658" height="475" srcset="https://d9m.one/wp-content/uploads/2022/07/TandH_021.png 877w, https://d9m.one/wp-content/uploads/2022/07/TandH_021-300x217.png 300w, https://d9m.one/wp-content/uploads/2022/07/TandH_021-768x554.png 768w" sizes="(max-width: 658px) 100vw, 658px" /></a><figcaption>動作確認</figcaption></figure>



<p class="has-medium-font-size"><strong>・プレビュー開始</strong></p>



<ol class="wp-block-list"><li>エディタ上中央の「▶」をクリック</li></ol>



<p class="has-medium-font-size"><strong>・動作確認</strong></p>



<ol class="wp-block-list"><li>タマとヒシガタが動いていないことを確認</li><li>ゲームビューをクリックしたらジャンプ台と隣接しているタマが動き出すことを確認</li></ol>



<p class="has-medium-font-size"><strong>・プレビュー終了</strong></p>



<ol class="wp-block-list"><li>エディタ上中央の「▶」をクリック</li></ol>
</div>



<h4 class="wp-block-heading"><span id="toc13">▷スクリプト記述例</span></h4>



<div class="wp-block-group is-layout-flow wp-block-group-is-layout-flow">
<p>「クリックしたらタマが動き出す」スクリプトの記述例です。</p>



<div class="hcb_wrap"><pre class="prism line-numbers lang-csharp" data-file="CharCtrl" data-lang="C#"><code>using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class CharCtrl : MonoBehaviour
{
    bool moveFlag = false;      // 移動中かどうか
    float moveFrame = 30;       // １歩に何フレームかけるか
    float frameCount = 0;       // 経過フレーム数

    // Start is called before the first frame update
    void Start()
    {
        
    }

    // Update is called once per frame
    void Update()
    {
        // マウスクリックされた場合
        if (Input.GetMouseButtonUp(0) == true)
        {
            // 現在の回転値を保存
            Quaternion rot = transform.rotation;
            // 上下左右のオブジェクトを取得
            transform.rotation = Quaternion.Euler(0, 0, 0);
            GameObject objU = GetObject(transform.position + transform.forward);
            GameObject objD = GetObject(transform.position - transform.forward);
            GameObject objL = GetObject(transform.position - transform.right);
            GameObject objR = GetObject(transform.position + transform.right);
            // 指定方向がジャンプ台かつ逆側がなにも無いかトゲの場合、オブジェクトをジャンプ台の逆側に向ける
            float dir = -1;
            if (objU != null && objU.tag == &quot;Jump&quot; && (objD == null || objD.tag == &quot;Toge&quot;)) dir = 180;
            if (objD != null && objD.tag == &quot;Jump&quot; && (objU == null || objU.tag == &quot;Toge&quot;)) dir = 0;
            if (objL != null && objL.tag == &quot;Jump&quot; && (objR == null || objR.tag == &quot;Toge&quot;)) dir = 90;
            if (objR != null && objR.tag == &quot;Jump&quot; && (objL == null || objL.tag == &quot;Toge&quot;)) dir = 270;
            if (dir != -1)
            {
                moveFlag = true;
                rot = Quaternion.Euler(0, dir, 0);
            }
            // 回転値を設定
            transform.rotation = rot;
        }
    }

    // 物理フレーム更新時に処理
    void FixedUpdate()
    {
        // タグ検索でタマとヒシガタの一覧を取得する
        GameObject[] tamas = GameObject.FindGameObjectsWithTag(&quot;Player&quot;);
        GameObject[] hisis = GameObject.FindGameObjectsWithTag(&quot;Enemy&quot;);

        // １歩分のフレームが経過するまで何もしない
        frameCount++;
        if (frameCount &lt; moveFrame) return;

        // 経過フレーム数を0初期化する
        frameCount = 0;

        // 移動していない場合は終了
        if (moveFlag == false) return;

        // 移動先に壁かジャンプ台があったら移動終了
        GameObject moveObj = GetObject(transform.position + transform.forward);
        if (moveObj != null && (moveObj.tag == &quot;Block&quot; || moveObj.tag == &quot;Jump&quot;))
        {
            moveFlag = false;
            return;
        }

        // 向いている方向に１メートル進む
        transform.position += transform.forward;

        // ヒシガタとタマが衝突したら両方削除
        if (tamas.Length != 0 && hisis.Length != 0)
        {
            // タマとヒシガタの位置が同じだった場合
            if (tamas[0].transform.position == hisis[0].transform.position)
            {
                // タマとヒシガタを削除
                Destroy(tamas[0]);
                Destroy(hisis[0]);
            }
        }

        // 重なったオブジェクトを取得
        GameObject obj = GetObject(transform.position);
        // トゲと重なったら自分とトゲを削除
        if (obj != null && obj.tag == &quot;Toge&quot;)
        {
            Destroy(gameObject);
            Destroy(obj);
        }
    }

    // 指定位置にあるオブジェクトを取得
    GameObject GetObject(Vector3 pos)
    {
        // 小数点誤差を補正
        float posX = Mathf.Floor(pos.x + 0.5f);
        float posZ = Mathf.Floor(pos.z + 0.5f);
        // 処理対象とするタグの一覧を作成
        string[] tags = new string[] { &quot;Toge&quot;, &quot;Block&quot;, &quot;Jump&quot; };
        // タグを１つ１つ処理
        for (int i = 0; i &lt; tags.Length; i++)
        {
            // 指定タグのオブジェクト一覧を取得
            GameObject[] objs = GameObject.FindGameObjectsWithTag(tags[i]);
            // オブジェクトを１つ１つ処理
            for (int j = 0; j &lt; objs.Length; j++)
            {
                // 指定位置に存在するオブジェクトを返す
                Vector3 objPos = objs[j].transform.position;
                if (objPos.x == posX && objPos.z == posZ) return objs[j];
            }
        }

        // 指定位置にオブジェクトが無いのでNULLを返す
        return null;
    }
}</code></pre></div>
</div>
</div>



<div style="height:16px" aria-hidden="true" class="wp-block-spacer"></div>



<h3 class="has-background has-medium-font-size wp-block-heading" style="background-color:#e5f7fd"><span id="toc14">●ゴール作成</span></h3>



<div style="height:16px" aria-hidden="true" class="wp-block-spacer"></div>



<div class="wp-block-group is-layout-flow wp-block-group-is-layout-flow">
<p>タマと衝突するとクリアになる、「ゴール」を作成します。</p>



<h4 class="wp-block-heading"><span id="toc15">▷ゴール作成</span></h4>



<div class="wp-block-group is-layout-flow wp-block-group-is-layout-flow">
<p>パーティクルシステムを作成して位置を(0, 0, 3)とし、その場に留まって揺らめくエフェクトとします。</p>



<figure class="wp-block-image size-full is-resized"><a href="https://d9m.one/wp-content/uploads/2022/07/TandH_022.png"><img decoding="async" src="https://d9m.one/wp-content/uploads/2022/07/TandH_022.png" alt="" class="wp-image-839" width="658" height="475" srcset="https://d9m.one/wp-content/uploads/2022/07/TandH_022.png 877w, https://d9m.one/wp-content/uploads/2022/07/TandH_022-300x217.png 300w, https://d9m.one/wp-content/uploads/2022/07/TandH_022-768x554.png 768w" sizes="(max-width: 658px) 100vw, 658px" /></a><figcaption>ゴール作成</figcaption></figure>



<p class="has-medium-font-size"><strong>・パーティクルシステム作成</strong></p>



<ol class="wp-block-list"><li>ヒエラルキー左上の「＋」をクリック</li><li>「エフェクト＞パーティクルシステム」をクリック</li><li>「Goal」と入力し、ENTERキーを押す</li></ol>



<p class="has-medium-font-size"><strong><strong>・<strong>位置、回転、スケール設定</strong></strong></strong></p>



<ol class="wp-block-list"><li>インスペクターのTransformにある位置を(0, 0, 3)とする</li><li>インスペクターのTransformにある回転を(-90, 0, 0)とする</li><li>インスペクターのTransformにあるスケールを(1, 1, 1)とする</li></ol>



<p class="has-medium-font-size"><strong>・メインモジュール設定</strong></p>



<p>メインモジュールを以下のように設定します。</p>



<ol class="wp-block-list"><li>インスペクターにあるParticle Systemの「メインモジュール＞継続時間」を(1)に設定</li><li>インスペクターにあるParticle Systemの「メインモジュール＞開始時の生存期間」を(1)に設定</li><li>インスペクターにあるParticle Systemの「メインモジュール＞開始時の速度」を(0)に設定</li><li>インスペクターにあるParticle Systemの「メインモジュール＞開始時の色」右にあるカラーバーをクリックし、色ダイアログの16進数を(FFFF00)に設定</li><li>色ダイアログの右上にある「×」をクリック</li><li>インスペクターにあるParticle Systemの「メインモジュール＞重力モディファイア」を(-0.1）に設定</li></ol>



<p class="has-medium-font-size"><strong>・形状モジュール設定</strong></p>



<p>形状モジュールを以下のように設定します。</p>



<ol class="wp-block-list"><li>形状モジュールの「形状」を(スフィア)に設定</li><li>形状モジュールの「半径」を(0.3)に設定</li><li>形状モジュールの「半径の厚さ」を(0)に設定</li></ol>
</div>



<h4 class="wp-block-heading"><span id="toc16">▷ゴール認識</span></h4>



<div class="wp-block-group is-layout-flow wp-block-group-is-layout-flow">
<p>タグ「Goal」を作成し、ゴールに割り当てます。</p>



<figure class="wp-block-image size-full is-resized"><a href="https://d9m.one/wp-content/uploads/2022/07/TandH_023.png"><img decoding="async" src="https://d9m.one/wp-content/uploads/2022/07/TandH_023.png" alt="" class="wp-image-841" width="658" height="475" srcset="https://d9m.one/wp-content/uploads/2022/07/TandH_023.png 877w, https://d9m.one/wp-content/uploads/2022/07/TandH_023-300x217.png 300w, https://d9m.one/wp-content/uploads/2022/07/TandH_023-768x554.png 768w" sizes="(max-width: 658px) 100vw, 658px" /></a><figcaption>ゴール認識</figcaption></figure>



<p class="has-medium-font-size"><strong>・タグ作成</strong></p>



<ol class="wp-block-list"><li>ヒエラルキーの「Goal」をクリック</li><li>インスペクター上部のタグドロップダウンをクリックし、「タグを追加&#8230;」をクリック</li><li>インスペクター「Tag &amp; Layers」にあるタグ欄右下の「＋」をクリック</li><li>「Goal」と入力してENTERを押す</li></ol>



<p class="has-medium-font-size"><strong>・タグ割り当て</strong></p>



<ol class="wp-block-list"><li>ヒエラルキーの「Goal」をクリック</li><li>インスペクター上部のタグドロップダウンをクリックし、「Goal」をクリック</li></ol>
</div>



<h4 class="wp-block-heading"><span id="toc17">▷ゴール制御</span></h4>



<div class="wp-block-group is-layout-flow wp-block-group-is-layout-flow">
<p>タマとゴールが衝突した時にタマとヒシガタの動きが止まるようにCharCtrlを修正します。</p>



<figure class="wp-block-image size-full is-resized"><a href="https://d9m.one/wp-content/uploads/2022/07/TandH_024.png"><img decoding="async" src="https://d9m.one/wp-content/uploads/2022/07/TandH_024.png" alt="" class="wp-image-843" width="658" height="475" srcset="https://d9m.one/wp-content/uploads/2022/07/TandH_024.png 877w, https://d9m.one/wp-content/uploads/2022/07/TandH_024-300x217.png 300w, https://d9m.one/wp-content/uploads/2022/07/TandH_024-768x554.png 768w" sizes="(max-width: 658px) 100vw, 658px" /></a><figcaption>ゴール制御</figcaption></figure>



<p class="has-medium-font-size"><strong>・スクリプト編集開始</strong></p>



<ol class="wp-block-list"><li>プロジェクトの「Assets&gt;CharCtrl」をダブルクリック</li></ol>



<p class="has-medium-font-size"><strong>・スクリプト変数追加</strong></p>



<ol class="wp-block-list"><li>「移動中かどうか」の変数の前に「プレイ中かどうか」の変数を作成</li></ol>



<div class="hcb_wrap"><pre class="prism line-numbers lang-csharp" data-file="CharCtrl" data-lang="C#"><code>    bool playFlag = true;       // プレイ中かどうか
</code></pre></div>



<p class="has-medium-font-size"><strong>・スクリプト関数修正</strong></p>



<ol class="wp-block-list"><li>FixedUpdate関数の先頭に以下の処理を追加</li></ol>



<div class="hcb_wrap"><pre class="prism line-numbers lang-csharp" data-file="CharCtrl" data-lang="C#"><code>        // プレイ中でない場合は即関数を終了
        if (playFlag == false) return;
</code></pre></div>



<p class="has-medium-font-size"><strong>・スクリプト<strong>関数修正</strong></strong></p>



<ol class="wp-block-list"><li>FixedUpdate関数の最後に以下の処理を追加</li></ol>



<div class="hcb_wrap"><pre class="prism line-numbers lang-csharp" data-file="CharCtrl" data-lang="C#"><code>        // 自分がタマで、かつゴールと重なった場合
        else if (tag == &quot;Player&quot; && obj != null && obj.tag == &quot;Goal&quot;)
        {
            // タマのplayFlagをfalseに設定
            playFlag = false;
        }
</code></pre></div>



<p class="has-medium-font-size"><strong>・スクリプト<strong>関数修正</strong></strong></p>



<ol class="wp-block-list"><li>GetObject関数内の「処理対象とするタグの一覧を作成」を以下のスクリプトのように修正</li></ol>



<div class="hcb_wrap"><pre class="prism line-numbers lang-csharp" data-file="CharCtrl" data-lang="C#"><code>        // 処理対象とするタグの一覧を作成
        string[] tags = new string[] { &quot;Toge&quot;, &quot;Block&quot;, &quot;Jump&quot;, &quot;Goal&quot; };
</code></pre></div>



<p class="has-medium-font-size"><strong><strong>・スクリプト保存</strong></strong></p>



<ol class="wp-block-list"><li>CTRLを押しながらSキーを押す</li></ol>



<p class="has-medium-font-size"><strong><strong><strong><strong>・Unityに戻ってスクリプトをビルド</strong></strong></strong></strong></p>



<ol class="wp-block-list"><li>Unityエディタのタイトルをクリック</li></ol>



<p class="has-medium-font-size"><strong><strong>・プロジェクト保存</strong></strong></p>



<ol class="wp-block-list"><li>CTRLを押しながらSキーを押す</li></ol>
</div>



<h4 class="wp-block-heading"><span id="toc18">▷動作確認</span></h4>



<div class="wp-block-group is-layout-flow wp-block-group-is-layout-flow">
<p>タマとゴールが衝突したらタマの動きが止まるかどうか、プレビューして確認します。</p>



<figure class="wp-block-image size-full is-resized"><a href="https://d9m.one/wp-content/uploads/2022/07/TandH_025.png"><img decoding="async" src="https://d9m.one/wp-content/uploads/2022/07/TandH_025.png" alt="" class="wp-image-844" width="658" height="475" srcset="https://d9m.one/wp-content/uploads/2022/07/TandH_025.png 877w, https://d9m.one/wp-content/uploads/2022/07/TandH_025-300x217.png 300w, https://d9m.one/wp-content/uploads/2022/07/TandH_025-768x554.png 768w" sizes="(max-width: 658px) 100vw, 658px" /></a><figcaption>動作確認</figcaption></figure>



<p class="has-medium-font-size"><strong>・プレビュー開始</strong></p>



<ol class="wp-block-list"><li>エディタ上中央の「▶」をクリック</li></ol>



<p class="has-medium-font-size"><strong><strong>・動作確認</strong></strong></p>



<ol class="wp-block-list"><li>タマとゴールが衝突したらタマの動きが止まることを確認</li></ol>



<p class="has-medium-font-size"><strong>・プレビュー終了</strong></p>



<ol class="wp-block-list"><li>エディタ上中央の「▶」をクリック</li></ol>
</div>



<h4 class="wp-block-heading"><span id="toc19">▷スクリプト記述例</span></h4>



<div class="wp-block-group is-layout-flow wp-block-group-is-layout-flow">
<p>「タマとゴールが衝突したらタマの動きが止まる」スクリプトの記述例です。</p>



<div class="hcb_wrap"><pre class="prism line-numbers lang-csharp" data-file="CharCtrl" data-lang="C#"><code>using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class CharCtrl : MonoBehaviour
{
    bool playFlag = true;       // プレイ中かどうか
    bool moveFlag = false;      // 移動中かどうか
    float moveFrame = 30;       // １歩に何フレームかけるか
    float frameCount = 0;       // 経過フレーム数

    // Start is called before the first frame update
    void Start()
    {
        
    }

    // Update is called once per frame
    void Update()
    {
        // マウスクリックされた場合
        if (Input.GetMouseButtonUp(0) == true)
        {
            // 現在の回転値を保存
            Quaternion rot = transform.rotation;
            // 上下左右のオブジェクトを取得
            transform.rotation = Quaternion.Euler(0, 0, 0);
            GameObject objU = GetObject(transform.position + transform.forward);
            GameObject objD = GetObject(transform.position - transform.forward);
            GameObject objL = GetObject(transform.position - transform.right);
            GameObject objR = GetObject(transform.position + transform.right);

            // 指定方向がジャンプ台かつ逆側がなにも無いかトゲの場合、オブジェクトをジャンプ台の逆側に向ける
            float dir = -1;
            if (objU != null && objU.tag == &quot;Jump&quot; && (objD == null || objD.tag == &quot;Toge&quot;)) dir = 180;
            if (objD != null && objD.tag == &quot;Jump&quot; && (objU == null || objU.tag == &quot;Toge&quot;)) dir = 0;
            if (objL != null && objL.tag == &quot;Jump&quot; && (objR == null || objR.tag == &quot;Toge&quot;)) dir = 90;
            if (objR != null && objR.tag == &quot;Jump&quot; && (objL == null || objL.tag == &quot;Toge&quot;)) dir = 270;
            if (dir != -1)
            {
                moveFlag = true;
                rot = Quaternion.Euler(0, dir, 0);
            }
            // 回転値を設定
            transform.rotation = rot;
        }
    }

    // 物理フレーム更新時に処理
    void FixedUpdate()
    {
        // プレイ中でない場合は即関数を終了
        if (playFlag == false) return;

        // タグ検索でタマとヒシガタの一覧を取得する
        GameObject[] tamas = GameObject.FindGameObjectsWithTag(&quot;Player&quot;);
        GameObject[] hisis = GameObject.FindGameObjectsWithTag(&quot;Enemy&quot;);

        // １歩分のフレームが経過するまで何もしない
        frameCount++;
        if (frameCount &lt; moveFrame) return;

        // 経過フレーム数を0初期化する
        frameCount = 0;

        // 移動していない場合は終了
        if (moveFlag == false) return;

        // 移動先に壁かジャンプ台があったら移動終了
        GameObject moveObj = GetObject(transform.position + transform.forward);
        if (moveObj != null && (moveObj.tag == &quot;Block&quot; || moveObj.tag == &quot;Jump&quot;))
        {
            moveFlag = false;
            return;
        }

        // 向いている方向に１メートル進む
        transform.position += transform.forward;

        // ヒシガタとタマが衝突したら両方削除
        if (tamas.Length != 0 && hisis.Length != 0)
        {
            // タマとヒシガタの位置が同じだった場合
            if (tamas[0].transform.position == hisis[0].transform.position)
            {
                // タマとヒシガタを削除
                Destroy(tamas[0]);
                Destroy(hisis[0]);
            }
        }

        // 重なったオブジェクトを取得
        GameObject obj = GetObject(transform.position);
        // トゲと重なったら自分とトゲを削除
        if (obj != null && obj.tag == &quot;Toge&quot;)
        {
            Destroy(gameObject);
            Destroy(obj);
        }
        // 自分がタマで、かつゴールと重なった場合
        else if (tag == &quot;Player&quot; && obj != null && obj.tag == &quot;Goal&quot;)
        {
            // タマのplayFlagをfalseに設定
            playFlag = false;
        }
    }

    // 指定位置にあるオブジェクトを取得
    GameObject GetObject(Vector3 pos)
    {
        // 小数点誤差を補正
        float posX = Mathf.Floor(pos.x + 0.5f);
        float posZ = Mathf.Floor(pos.z + 0.5f);
        // 処理対象とするタグの一覧を作成
        string[] tags = new string[] { &quot;Toge&quot;, &quot;Block&quot;, &quot;Jump&quot;, &quot;Goal&quot; };
        // タグを１つ１つ処理
        for (int i = 0; i &lt; tags.Length; i++)
        {
            // 指定タグのオブジェクト一覧を取得
            GameObject[] objs = GameObject.FindGameObjectsWithTag(tags[i]);
            // オブジェクトを１つ１つ処理
            for (int j = 0; j &lt; objs.Length; j++)
            {
                // 指定位置に存在するオブジェクトを返す
                Vector3 objPos = objs[j].transform.position;
                if (objPos.x == posX && objPos.z == posZ) return objs[j];
            }
        }

        // 指定位置にオブジェクトが無いのでNULLを返す
        return null;
    }
}
</code></pre></div>
</div>
</div>



<p>作成手順を書いた記事です。</p>



<p>　　　<a href="https://d9m.one/proc_tandh/" type="URL" id="https://d9m.one/proc_tandh">→紹介</a><br>　　　<a href="https://d9m.one/proc_tandh1/" type="URL" id="https://d9m.one/proc_tandh1">→１／３　キャラクター作成</a><br>今▷　<a href="https://d9m.one/proc_tandh2/" type="URL" id="https://d9m.one/proc_tandh2">→２／３　オブジェクト作成</a><br>次▷　<a href="https://d9m.one/proc_tandh3/" type="URL" id="https://d9m.one/proc_tandh3">→３／３　ゲーム仕上げ</a></p>



<p><a href="https://d9m.one/proc_tandh_full/" type="URL" id="https://d9m.one/proc_tandh_full">完全手順</a><br>※紹介と１～３の手順を１ページにまとめています。<br>　読み込みに時間がかかるかも知れません。</p>



<div style="height:16px" aria-hidden="true" class="wp-block-spacer"></div>
<p>投稿 <a href="https://d9m.one/proc_tandh2/">【基本操作】タマあんどヒシガタ～２／３　オブジェクト作成【パズル】</a> は <a href="https://d9m.one">だくまたゲーム制作ブログ</a> に最初に表示されました。</p>
]]></content:encoded>
					
					<wfw:commentRss>https://d9m.one/proc_tandh2/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>【基本操作】タマあんどヒシガタ～１／３　キャラクター作成【パズル】</title>
		<link>https://d9m.one/proc_tandh1/</link>
					<comments>https://d9m.one/proc_tandh1/#respond</comments>
		
		<dc:creator><![CDATA[だくまた]]></dc:creator>
		<pubDate>Fri, 22 Jul 2022 09:34:00 +0000</pubDate>
				<category><![CDATA[Unity]]></category>
		<category><![CDATA[基本操作]]></category>
		<category><![CDATA[自作ゲーム]]></category>
		<category><![CDATA[チュートリアル]]></category>
		<guid isPermaLink="false">https://d9m.one/?p=945</guid>

					<description><![CDATA[<p>●タマ作成 最初にプレイヤーとして動かすタマを作成します。タマの隣にジャンプ台がある時に画面をクリックすると、ジャンプ台に押したように動き出します。まずは単純に、いきなり進み続けるように作成します。 ▷タマ作成 球を作成 [&#8230;]</p>
<p>投稿 <a href="https://d9m.one/proc_tandh1/">【基本操作】タマあんどヒシガタ～１／３　キャラクター作成【パズル】</a> は <a href="https://d9m.one">だくまたゲーム制作ブログ</a> に最初に表示されました。</p>
]]></description>
										<content:encoded><![CDATA[
<div style="height:16px" aria-hidden="true" class="wp-block-spacer"></div>



<h3 class="has-background has-medium-font-size wp-block-heading" style="background-color:#e5f7fd"><span id="toc1">●タマ作成</span></h3>



<div style="height:16px" aria-hidden="true" class="wp-block-spacer"></div>



<div class="wp-block-group is-layout-flow wp-block-group-is-layout-flow">
<p>最初にプレイヤーとして動かすタマを作成します。<br>タマの隣にジャンプ台がある時に画面をクリックすると、ジャンプ台に押したように動き出します。<br>まずは単純に、いきなり進み続けるように作成します。</p>



<h4 class="wp-block-heading"><span id="toc2">▷タマ作成</span></h4>



<div class="wp-block-group is-layout-flow wp-block-group-is-layout-flow">
<p>球を作成してTransformをリセットし、青色設定したマテリアルを割り当てます。</p>



<figure class="wp-block-image size-full is-resized"><a href="https://d9m.one/wp-content/uploads/2022/07/TandH_000.png"><img decoding="async" src="https://d9m.one/wp-content/uploads/2022/07/TandH_000.png" alt="" class="wp-image-807" width="658" height="475" srcset="https://d9m.one/wp-content/uploads/2022/07/TandH_000.png 877w, https://d9m.one/wp-content/uploads/2022/07/TandH_000-300x217.png 300w, https://d9m.one/wp-content/uploads/2022/07/TandH_000-768x554.png 768w" sizes="(max-width: 658px) 100vw, 658px" /></a><figcaption>タマ作成</figcaption></figure>



<p class="has-medium-font-size"><strong>・球作成</strong></p>



<ol class="wp-block-list"><li>ヒエラルキー左上の「＋」をクリック</li><li>「3Dオブジェクト＞スフィア」をクリック</li><li>「Tama」と入力し、ENTERキーを押す</li></ol>



<p class="has-medium-font-size"><strong>・位置、回転、スケールリセット</strong></p>



<ol class="wp-block-list"><li>インスペクターのTransformにある縦の三点リーダーをクリック</li><li>リセットをクリック</li></ol>



<p class="has-medium-font-size"><strong>・マテリアル作成</strong></p>



<ol class="wp-block-list"><li>プロジェクトの「Assets」を右クリックし、「作成＞マテリアル」をクリック</li><li>「matTama」と入力し、ENTERキーを押す</li></ol>



<p class="has-medium-font-size"><strong>・マテリアル色設定</strong></p>



<ol class="wp-block-list"><li>インスペクターの「Main Maps&gt;アルベド＞カラーバー」をクリックし、色ダイアログの16進数を「0000FF」に設定</li><li>色ダイアログの右上にある「×」をクリック</li></ol>



<p class="has-medium-font-size"><strong>・マテリアル割り当て</strong></p>



<ol class="wp-block-list"><li>プロジェクトの「matTama」をヒエラルキーの「Tama」にドラッグ＆ドロップ</li></ol>
</div>



<h4 class="wp-block-heading"><span id="toc3">▷タマ制御</span></h4>



<div class="wp-block-group is-layout-flow wp-block-group-is-layout-flow">
<p>スクリプトを作成してタマに割り当て、「タマを30フレームに1メートルの速さで動く」ようにスクリプトを記述します。</p>



<figure class="wp-block-image size-full is-resized"><a href="https://d9m.one/wp-content/uploads/2022/07/TandH_001.png"><img decoding="async" src="https://d9m.one/wp-content/uploads/2022/07/TandH_001.png" alt="" class="wp-image-808" width="658" height="475" srcset="https://d9m.one/wp-content/uploads/2022/07/TandH_001.png 877w, https://d9m.one/wp-content/uploads/2022/07/TandH_001-300x217.png 300w, https://d9m.one/wp-content/uploads/2022/07/TandH_001-768x554.png 768w" sizes="(max-width: 658px) 100vw, 658px" /></a><figcaption>タマ制御</figcaption></figure>



<p class="has-medium-font-size"><strong>・スクリプト作成</strong></p>



<ol class="wp-block-list"><li>プロジェクトの「Assets」を右クリックし、「作成＞C# スクリプト」をクリック</li><li>「CharCtrl」と入力し、ENTERキーを押す</li></ol>



<p class="has-medium-font-size"><strong>・スクリプト割り当て</strong></p>



<ol class="wp-block-list"><li>プロジェクトの「Assets&gt;CharCtrl」をヒエラルキーの「Tama」にドラッグ＆ドロップ</li></ol>



<p class="has-medium-font-size"><strong>・スクリプト編集開始</strong></p>



<ol class="wp-block-list"><li>プロジェクトの「Assets&gt;CharCtrl」をダブルクリック</li></ol>



<p class="has-medium-font-size"><strong>・スクリプト変数定義</strong></p>



<ol class="wp-block-list"><li>クラス定義内の先頭に以下の変数を追加</li></ol>



<div class="hcb_wrap"><pre class="prism line-numbers lang-csharp" data-file="CharCtrl.cs" data-lang="C#"><code>    float moveFrame = 30;       // １歩に何フレームかけるか
    float frameCount = 0;       // 経過フレーム数
</code></pre></div>



<p class="has-medium-font-size"><strong>・スクリプト関数定義</strong></p>



<ol class="wp-block-list"><li>クラス定義内の最後に以下の関数を追加</li></ol>



<div class="hcb_wrap"><pre class="prism line-numbers lang-csharp" data-file="CharCtrl.cs" data-lang="C#"><code>    // 物理フレーム更新時に処理
    void FixedUpdate()
    {
    }
</code></pre></div>



<p class="has-medium-font-size">・<strong>スクリプト処理</strong></p>



<ol class="wp-block-list" id="block-df2c71c8-85d2-454d-ba7a-555e235c2226"><li>FixedFrameに以下の処理を記述</li></ol>



<div class="hcb_wrap"><pre class="prism line-numbers lang-csharp" data-file="CharCtrl.cs" data-lang="C#"><code>        // １歩分のフレームが経過するまで何もしない
        frameCount++;
        if (frameCount &lt; moveFrame) return;

        // 経過フレーム数を0初期化する
        frameCount = 0;

        // 向いている方向に１メートル進む
        transform.position += transform.forward;
</code></pre></div>



<p class="has-medium-font-size"><strong>・スクリプト保存</strong></p>



<ol class="wp-block-list"><li>CTRLを押しながらSキーを押す</li></ol>



<p class="has-medium-font-size"><strong>・Unityに戻ってスクリプトをビルド</strong></p>



<ol class="wp-block-list" id="block-d832c413-6256-49d3-b625-25f4086a75c5"><li>Unityエディタのタイトルをクリック</li></ol>
</div>



<h4 class="wp-block-heading"><span id="toc4">▷タマ認識</span></h4>



<div class="wp-block-group is-layout-flow wp-block-group-is-layout-flow">
<p>スクリプトでタマを認識させるため、タグ「Player」をタマに割り当てます。</p>



<figure class="wp-block-image size-full is-resized"><a href="https://d9m.one/wp-content/uploads/2022/07/TandH_002.png"><img decoding="async" src="https://d9m.one/wp-content/uploads/2022/07/TandH_002.png" alt="" class="wp-image-809" width="658" height="475" srcset="https://d9m.one/wp-content/uploads/2022/07/TandH_002.png 877w, https://d9m.one/wp-content/uploads/2022/07/TandH_002-300x217.png 300w, https://d9m.one/wp-content/uploads/2022/07/TandH_002-768x554.png 768w" sizes="(max-width: 658px) 100vw, 658px" /></a><figcaption>タマ認識</figcaption></figure>



<p class="has-medium-font-size"><strong>・タグ割り当て</strong></p>



<ol class="wp-block-list" id="block-d832c413-6256-49d3-b625-25f4086a75c5"><li>ヒエラルキーの「Tama」をクリック</li><li>インスペクター上部のタグドロップダウンをクリックし、「Player」をクリック</li></ol>



<p class="has-medium-font-size"><strong><strong>・プロジェクト保存</strong></strong></p>



<ol class="wp-block-list"><li>CTRLを押しながらSキーを押す</li></ol>
</div>



<h4 class="wp-block-heading"><span id="toc5">▷動作確認</span></h4>



<div class="wp-block-group is-layout-flow wp-block-group-is-layout-flow">
<p>タマが期待通り動くかどうか、プレビューして確認します。</p>



<figure class="wp-block-image size-full is-resized"><a href="https://d9m.one/wp-content/uploads/2022/07/TandH_003.png"><img decoding="async" src="https://d9m.one/wp-content/uploads/2022/07/TandH_003.png" alt="" class="wp-image-810" width="658" height="475" srcset="https://d9m.one/wp-content/uploads/2022/07/TandH_003.png 877w, https://d9m.one/wp-content/uploads/2022/07/TandH_003-300x217.png 300w, https://d9m.one/wp-content/uploads/2022/07/TandH_003-768x554.png 768w" sizes="(max-width: 658px) 100vw, 658px" /></a><figcaption>動作確認</figcaption></figure>



<p class="has-medium-font-size"><strong>・プレビュー</strong>開始</p>



<ol class="wp-block-list"><li>エディタ上中央の「▶」をクリック</li></ol>



<p class="has-medium-font-size"><strong>・動作確認</strong></p>



<ol class="wp-block-list"><li>奥に向かって１メートルごとに進むことを確認</li></ol>



<p class="has-medium-font-size"><strong>・プレビュー</strong>終了</p>



<ol class="wp-block-list"><li>エディタ上中央の「▶」をクリック</li></ol>
</div>



<h4 class="wp-block-heading"><span id="toc6">▷スクリプト記述例</span></h4>



<div class="wp-block-group is-layout-flow wp-block-group-is-layout-flow">
<p>「タマを30フレームに1メートルの速さで動く」スクリプトの記述例です。</p>



<div class="hcb_wrap"><pre class="prism line-numbers lang-csharp" data-file="CharCtrl.cs" data-lang="C#"><code>using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class CharCtrl : MonoBehaviour
{
    float moveFrame = 30;       // １歩に何フレームかけるか
    float frameCount = 0;       // 経過フレーム数

    // Start is called before the first frame update
    void Start()
    {
        
    }

    // Update is called once per frame
    void Update()
    {
        
    }

    // 物理フレーム更新時に処理
    void FixedUpdate()
    {
        // １歩分のフレームが経過するまで何もしない
        frameCount++;
        if (frameCount &lt; moveFrame) return;

        // 経過フレーム数を0初期化する
        frameCount = 0;

        // 向いている方向に１メートル進む
        transform.position += transform.forward;
    }
}
</code></pre></div>
</div>



<div style="height:16px" aria-hidden="true" class="wp-block-spacer"></div>
</div>



<h3 class="has-background has-medium-font-size wp-block-heading" style="background-color:#e5f7fd"><span id="toc7">●ヒシガタ作成</span></h3>



<div class="wp-block-group is-layout-flow wp-block-group-is-layout-flow">
<div style="height:16px" aria-hidden="true" class="wp-block-spacer"></div>



<p>次に、同じように動くキャラクター「ヒシガタ」を作成します。<br>タマと衝突すると両方とも消滅します。</p>



<h4 class="wp-block-heading"><span id="toc8">▷ヒシガタ作成</span></h4>



<div class="wp-block-group is-layout-flow wp-block-group-is-layout-flow">
<p>箱を作成してTransformを「位置(0, 0, 0)、回転(0, 45, 0)、スケール(0.7, 1, 0.7)」とし、赤色設定したマテリアルを割り当てます。</p>



<figure class="wp-block-image size-full is-resized"><a href="https://d9m.one/wp-content/uploads/2022/07/TandH_004.png"><img decoding="async" src="https://d9m.one/wp-content/uploads/2022/07/TandH_004.png" alt="" class="wp-image-812" width="658" height="475" srcset="https://d9m.one/wp-content/uploads/2022/07/TandH_004.png 877w, https://d9m.one/wp-content/uploads/2022/07/TandH_004-300x217.png 300w, https://d9m.one/wp-content/uploads/2022/07/TandH_004-768x554.png 768w" sizes="(max-width: 658px) 100vw, 658px" /></a><figcaption>ヒシガタ作成</figcaption></figure>



<p class="has-medium-font-size"><strong>・箱作成</strong></p>



<ol class="wp-block-list"><li>ヒエラルキー左上の「＋」をクリック</li><li>「3Dオブジェクト＞キューブ」をクリック</li></ol>



<p class="has-medium-font-size"><strong>・位置、回転、スケール設定</strong></p>



<ol class="wp-block-list"><li>インスペクターのTransformにある位置を(0, 0, 0)とする</li><li>インスペクターのTransformにある回転を(0, 45, 0)とする</li><li>インスペクターのTransformにあるスケールを(0.7, 1, 0.7)とする</li></ol>



<p class="has-medium-font-size"><strong>・マテリアル作成</strong></p>



<ol class="wp-block-list"><li>プロジェクトの「Assets」を右クリックし、「作成＞マテリアル」をクリック</li><li>「matHisi」と入力し、ENTERキーを押す</li></ol>



<p class="has-medium-font-size"><strong>・マテリアル色設定</strong></p>



<ol class="wp-block-list"><li>インスペクターの「MainMaps&gt;アルベド＞カラーバー」をクリックし、色ダイアログの16進数を「FF0000」に設定</li><li>色ダイアログの右上にある「×」をクリック</li></ol>



<p class="has-medium-font-size"><strong>・マテリアル割り当て</strong></p>



<ol class="wp-block-list"><li>プロジェクトの「matHisi」をヒエラルキーの「Cube」にドラッグ＆ドロップ</li></ol>
</div>



<h4 class="wp-block-heading"><span id="toc9">▷ヒシガタ階層化</span></h4>



<div class="wp-block-group is-layout-flow wp-block-group-is-layout-flow">
<p>空オブジェクトを作成してTransformを「位置(1, 0, 0)、回転(0, 270, 0)、スケール(1, 1, 1)」とし、赤色の箱を子供とします。</p>



<figure class="wp-block-image size-full is-resized"><a href="https://d9m.one/wp-content/uploads/2022/07/TandH_005.png"><img decoding="async" src="https://d9m.one/wp-content/uploads/2022/07/TandH_005.png" alt="" class="wp-image-813" width="658" height="475" srcset="https://d9m.one/wp-content/uploads/2022/07/TandH_005.png 877w, https://d9m.one/wp-content/uploads/2022/07/TandH_005-300x217.png 300w, https://d9m.one/wp-content/uploads/2022/07/TandH_005-768x554.png 768w" sizes="(max-width: 658px) 100vw, 658px" /></a><figcaption>ヒシガタ階層化</figcaption></figure>



<p class="has-medium-font-size"><strong>・空オブジェクト作成</strong></p>



<ol class="wp-block-list"><li>ヒエラルキー左上の「＋」をクリック</li><li>「空のオブジェクトを作成」をクリック</li><li>「Hisi」と入力し、ENTERキーを押す</li></ol>



<p class="has-medium-font-size"><strong>・階層設定</strong></p>



<ol class="wp-block-list"><li>ヒエラルキーの「Cube」をヒエラルキーの「Hisi」にドラッグ＆ドロップ</li></ol>



<p class="has-medium-font-size"><strong>・位置、回転、スケール設定</strong></p>



<ol class="wp-block-list"><li>ヒエラルキーの「Hisi」をクリック</li><li>インスペクターのTransformにある位置を(3, 0, 3)とする</li><li>インスペクターのTransformにある回転を(0, 270, 0)とする</li><li>インスペクターのTransformにあるスケールを(1, 1, 1)とする</li></ol>
</div>



<h4 class="wp-block-heading"><span id="toc10">▷ヒシガタ認識</span></h4>



<div class="wp-block-group is-layout-flow wp-block-group-is-layout-flow">
<p>タグ「Enemy」を作成し、ヒシガタに割り当てます。</p>



<figure class="wp-block-image size-full is-resized"><a href="https://d9m.one/wp-content/uploads/2022/07/TandH_006.png"><img decoding="async" src="https://d9m.one/wp-content/uploads/2022/07/TandH_006.png" alt="" class="wp-image-814" width="658" height="475" srcset="https://d9m.one/wp-content/uploads/2022/07/TandH_006.png 877w, https://d9m.one/wp-content/uploads/2022/07/TandH_006-300x217.png 300w, https://d9m.one/wp-content/uploads/2022/07/TandH_006-768x554.png 768w" sizes="(max-width: 658px) 100vw, 658px" /></a><figcaption>ヒシガタ認識</figcaption></figure>



<p class="has-medium-font-size"><strong>・タグ作成</strong></p>



<ol class="wp-block-list" id="block-d832c413-6256-49d3-b625-25f4086a75c5"><li>ヒエラルキーの「Hisi」をクリック</li><li>インスペクター上部のタグドロップダウンをクリックし、「タグを追加&#8230;」をクリック</li><li>インスペクター「Tag &amp; Layers」にあるタグ欄右下の「＋」をクリック</li><li>「Enemy」と入力してENTERを押す</li></ol>



<p class="has-medium-font-size"><strong>・タグ割り当て</strong></p>



<ol class="wp-block-list" id="block-3f34234f-49e3-4ace-a1a6-ad25622ab28e"><li>ヒエラルキーの「Hisi」をクリック</li><li>インスペクターのタグドロップダウンをクリックし、「Enemy」をクリック</li></ol>
</div>



<h4 class="wp-block-heading"><span id="toc11">▷ヒシガタ制御</span></h4>



<div class="wp-block-group is-layout-flow wp-block-group-is-layout-flow">
<p>ヒシガタにCharCtrlを割り当て、CharCtrlを「タマとヒシガタが衝突したら両方削除する」ように修正します。</p>



<figure class="wp-block-image size-full is-resized"><a href="https://d9m.one/wp-content/uploads/2022/07/TandH_007.png"><img decoding="async" src="https://d9m.one/wp-content/uploads/2022/07/TandH_007.png" alt="" class="wp-image-815" width="658" height="475" srcset="https://d9m.one/wp-content/uploads/2022/07/TandH_007.png 877w, https://d9m.one/wp-content/uploads/2022/07/TandH_007-300x217.png 300w, https://d9m.one/wp-content/uploads/2022/07/TandH_007-768x554.png 768w" sizes="(max-width: 658px) 100vw, 658px" /></a><figcaption>ヒシガタ制御</figcaption></figure>



<p class="has-medium-font-size"><strong>・スクリプト割り当て</strong></p>



<ol class="wp-block-list"><li>プロジェクトの「Assets&gt;CharCtrl」をヒエラルキーの「Hisi」にドラッグ＆ドロップ</li></ol>



<p class="has-medium-font-size"><strong>・スクリプト編集開始</strong></p>



<ol class="wp-block-list"><li>プロジェクトの「Assets&gt;CharCtrl」をダブルクリック</li></ol>



<p class="has-medium-font-size"><strong>・タグでオブジェクトを検索</strong></p>



<ol class="wp-block-list"><li>FixedUpdate関数の処理先頭に「タグ検索でタマとヒシガタの一覧を取得する」処理を追加</li></ol>



<div class="hcb_wrap"><pre class="prism line-numbers lang-csharp" data-file="CharCtrl.cs" data-lang="C#"><code>        // タグ検索でタマとヒシガタの一覧を取得する
        GameObject[] tamas = GameObject.FindGameObjectsWithTag(&quot;Player&quot;);
        GameObject[] hisis = GameObject.FindGameObjectsWithTag(&quot;Enemy&quot;);
</code></pre></div>



<p class="has-medium-font-size"><strong>・衝突時にオブジェクトを削除</strong></p>



<ol class="wp-block-list"><li>移動処理の後に「ヒシガタとタマが衝突したら両方削除」する処理を追加</li></ol>



<div class="hcb_wrap"><pre class="prism line-numbers lang-csharp" data-file="CharCtrl.cs" data-lang="C#"><code>        // ヒシガタとタマが衝突したら両方削除
        if (tamas.Length != 0 && hisis.Length != 0)
        {
            // タマとヒシガタの位置が同じだった場合
            if (tamas[0].transform.position == hisis[0].transform.position)
            {
                // タマとヒシガタを削除
                Destroy(tamas[0]);
                Destroy(hisis[0]);
            }
        }
</code></pre></div>



<p class="has-medium-font-size"><strong>・スクリプト保存</strong></p>



<ol class="wp-block-list"><li>CTRLを押しながらSキーを押す</li></ol>



<p class="has-medium-font-size"><strong>・Unityに戻ってスクリプトをビルド</strong></p>



<ol class="wp-block-list" id="block-d832c413-6256-49d3-b625-25f4086a75c5"><li>Unityエディタのタイトルをクリック</li></ol>



<p class="has-medium-font-size"><strong>・プロジェクト保存</strong></p>



<ol class="wp-block-list"><li>CTRLを押しながらSキーを押す</li></ol>
</div>



<h4 class="wp-block-heading"><span id="toc12">▷動作確認</span></h4>



<div class="wp-block-group is-layout-flow wp-block-group-is-layout-flow">
<p>ヒシガタが期待通り動き、タマと衝突したら両方消えるかどうか、プレビューして確認します。</p>



<figure class="wp-block-image size-full is-resized"><a href="https://d9m.one/wp-content/uploads/2022/07/TandH_008.png"><img decoding="async" src="https://d9m.one/wp-content/uploads/2022/07/TandH_008.png" alt="" class="wp-image-816" width="658" height="475" srcset="https://d9m.one/wp-content/uploads/2022/07/TandH_008.png 877w, https://d9m.one/wp-content/uploads/2022/07/TandH_008-300x217.png 300w, https://d9m.one/wp-content/uploads/2022/07/TandH_008-768x554.png 768w" sizes="(max-width: 658px) 100vw, 658px" /></a><figcaption>動作確認</figcaption></figure>



<p class="has-medium-font-size"><strong>・プレビュー</strong>開始</p>



<ol class="wp-block-list"><li>エディタ上中央の「▶」をクリック</li></ol>



<p class="has-medium-font-size"><strong>・動作確認</strong></p>



<ol class="wp-block-list"><li>ヒシガタが左奥に向かって進むことを確認</li><li>タマとヒシガタがぶつかったら両方消えることを確認</li></ol>



<p class="has-medium-font-size"><strong>・プレビュー終了</strong></p>



<ol class="wp-block-list"><li>エディタ上中央の「▶」をクリック</li></ol>
</div>



<h4 class="wp-block-heading"><span id="toc13">▷スクリプト記述例</span></h4>



<div class="wp-block-group is-layout-flow wp-block-group-is-layout-flow">
<p>「タマとヒシガタが衝突したら両方削除する」スクリプトの記述例です。</p>



<div class="hcb_wrap"><pre class="prism line-numbers lang-csharp" data-file="CharCtrl.cs" data-lang="C#"><code>using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class CharCtrl : MonoBehaviour
{
    float moveFrame = 30;       // １歩に何フレームかけるか
    float frameCount = 0;       // 経過フレーム数

    // Start is called before the first frame update
    void Start()
    {
        
    }

    // Update is called once per frame
    void Update()
    {
        
    }

    // 物理フレーム更新時に処理
    void FixedUpdate()
    {
        // タグ検索でタマとヒシガタの一覧を取得する
        GameObject[] tamas = GameObject.FindGameObjectsWithTag(&quot;Player&quot;);
        GameObject[] hisis = GameObject.FindGameObjectsWithTag(&quot;Enemy&quot;);

        // １歩分のフレームが経過するまで何もしない
        frameCount++;
        if (frameCount &lt; moveFrame) return;

        // 経過フレーム数を0初期化する
        frameCount = 0;

        // 向いている方向に１メートル進む
        transform.position += transform.forward;

        // ヒシガタとタマが衝突したら両方削除
        if (tamas.Length != 0 && hisis.Length != 0)
        {
            // タマとヒシガタの位置が同じだった場合
            if (tamas[0].transform.position == hisis[0].transform.position)
            {
                // タマとヒシガタを削除
                Destroy(tamas[0]);
                Destroy(hisis[0]);
            }
        }
    }
}
</code></pre></div>
</div>



<div style="height:16px" aria-hidden="true" class="wp-block-spacer"></div>
</div>



<h3 class="has-background has-medium-font-size wp-block-heading" style="background-color:#e5f7fd"><span id="toc14">●トゲ作成</span></h3>



<div class="wp-block-group is-layout-flow wp-block-group-is-layout-flow">
<div style="height:16px" aria-hidden="true" class="wp-block-spacer"></div>



<p>動かないヒシガタである「トゲ」を作成します。<br>タマやヒシガタが衝突するとトゲとともに消滅します。</p>



<h4 class="wp-block-heading"><span id="toc15">▷トゲ作成</span></h4>



<div class="wp-block-group is-layout-flow wp-block-group-is-layout-flow">
<p>同じ構成なので、ヒシガタをコピーして利用します。<br>名前を変更して位置を(1, 0, 3)とし、色を紫に変更します。</p>



<figure class="wp-block-image size-full is-resized"><a href="https://d9m.one/wp-content/uploads/2022/07/TandH_009.png"><img decoding="async" src="https://d9m.one/wp-content/uploads/2022/07/TandH_009.png" alt="" class="wp-image-817" width="658" height="475" srcset="https://d9m.one/wp-content/uploads/2022/07/TandH_009.png 877w, https://d9m.one/wp-content/uploads/2022/07/TandH_009-300x217.png 300w, https://d9m.one/wp-content/uploads/2022/07/TandH_009-768x554.png 768w" sizes="(max-width: 658px) 100vw, 658px" /></a><figcaption>トゲ作成</figcaption></figure>



<p class="has-medium-font-size"><strong>・オブジェクト複製</strong></p>



<ol class="wp-block-list"><li>ヒエラルキーの「Hisi」をクリック</li><li>CTRLを押しながらDキーを押す</li></ol>



<p class="has-medium-font-size"><strong>・オブジェクト名変更</strong></p>



<ol class="wp-block-list"><li>F2キーを押す</li><li>「Toge」と入力し、ENTERキーを押す</li></ol>



<p class="has-medium-font-size"><strong>・位置設定</strong></p>



<ol class="wp-block-list"><li>インスペクターのTransformにある位置を(1, 0, 3)に設定</li></ol>



<p class="has-medium-font-size"><strong>・アセット複製</strong></p>



<ol class="wp-block-list"><li>プロジェクトの「Assets&gt;matHisi」をクリック</li><li>CTRLを押しながらDキーを押す</li></ol>



<p class="has-medium-font-size">・<strong>アセット名変更</strong></p>



<ol class="wp-block-list"><li>F2キーを押す</li><li>「matToge」を入力し、ENTERキーを押す</li></ol>



<p class="has-medium-font-size"><strong>・マテリアル色設定</strong></p>



<ol class="wp-block-list"><li>インスペクターの「Main Maps&gt;アルベド＞カラーバー」をクリックし、色ダイアログの16進数を「FF00FF」に設定</li><li>色ダイアログの右上にある「×」をクリック</li></ol>



<p class="has-medium-font-size"><strong>・マテリアル割り当て</strong></p>



<ol class="wp-block-list"><li>ヒエラルキーの「Toge」左にある「▶」をクリック</li><li>プロジェクトの「Assets&gt;matToge」をヒエラルキーの「Toge&gt;Cube」にドラッグ＆ドロップ</li></ol>
</div>



<h4 class="wp-block-heading"><span id="toc16">▷トゲ認識</span></h4>



<div class="wp-block-group is-layout-flow wp-block-group-is-layout-flow">
<p>タグ「Toge」を作成し、トゲに割り当てます。</p>



<figure class="wp-block-image size-full is-resized"><a href="https://d9m.one/wp-content/uploads/2022/07/TandH_010.png"><img decoding="async" src="https://d9m.one/wp-content/uploads/2022/07/TandH_010.png" alt="" class="wp-image-819" width="658" height="475" srcset="https://d9m.one/wp-content/uploads/2022/07/TandH_010.png 877w, https://d9m.one/wp-content/uploads/2022/07/TandH_010-300x217.png 300w, https://d9m.one/wp-content/uploads/2022/07/TandH_010-768x554.png 768w" sizes="(max-width: 658px) 100vw, 658px" /></a><figcaption>トゲ認識</figcaption></figure>



<p class="has-medium-font-size"><strong>・タグ作成</strong></p>



<ol class="wp-block-list"><li>ヒエラルキーの「Toge」をクリック</li><li>インスペクターのタグドロップダウンをクリックし、「タグを追加&#8230;」をクリック</li><li>インスペクター「Tag &amp; Layers」にあるタグ欄右下の「＋」をクリック</li><li>「Toge」と入力してENTERを押す</li></ol>



<p class="has-medium-font-size"><strong>・タグ割り当て</strong></p>



<ol class="wp-block-list"><li>ヒエラルキーの「Toge」をクリック</li><li>インスペクターのタグドロップダウンをクリックし、「Toge」をクリック</li></ol>
</div>



<h4 class="wp-block-heading"><span id="toc17">▷トゲ制御</span></h4>



<div class="wp-block-group is-layout-flow wp-block-group-is-layout-flow">
<p>トゲは動かないのでCharCtrlスクリプトを外します。<br>「自分（タマかヒシガタ）がトゲと衝突した時に両方消える」ようにCharCtrlを修正します。<br>結果、トゲとタマ、もしくはトゲとヒシガタが衝突した時に両方が消えるようになります。</p>



<figure class="wp-block-image size-full is-resized"><a href="https://d9m.one/wp-content/uploads/2022/07/TandH_011.png"><img decoding="async" src="https://d9m.one/wp-content/uploads/2022/07/TandH_011.png" alt="" class="wp-image-820" width="658" height="475" srcset="https://d9m.one/wp-content/uploads/2022/07/TandH_011.png 877w, https://d9m.one/wp-content/uploads/2022/07/TandH_011-300x217.png 300w, https://d9m.one/wp-content/uploads/2022/07/TandH_011-768x554.png 768w" sizes="(max-width: 658px) 100vw, 658px" /></a><figcaption>トゲ制御</figcaption></figure>



<p class="has-medium-font-size"><strong>・コンポーネント削除</strong></p>



<ol class="wp-block-list"><li>ヒエラルキーの「Toge」をクリック</li><li>インスペクターの「Char Ctrl(スクリプト)」にある縦の三点リーダーをクリック</li><li>「コンポーネントを削除」をクリック</li></ol>



<p class="has-medium-font-size"><strong>・スクリプト編集開始</strong></p>



<ol class="wp-block-list"><li>プロジェクトの「Assets&gt;CharCtrl」をダブルクリック</li></ol>



<p class="has-medium-font-size"><strong>・スクリプト関数定義</strong></p>



<ol class="wp-block-list"><li>FixedUpdate関数の後に以下の関数を追加</li></ol>



<div class="hcb_wrap"><pre class="prism line-numbers lang-csharp" data-file="CharCtrl.cs" data-lang="C#"><code>    // 指定位置にあるオブジェクトを取得
    GameObject GetObject(Vector3 pos)
    {
        // 指定位置にオブジェクトが無いのでNULLを返す
        return null;
    }
</code></pre></div>



<p class="has-medium-font-size"><strong>・スクリプト関数作成</strong></p>



<ol class="wp-block-list"><li>GetObject内の「指定位置にオブジェクトが無いのでNULLを返す」前に以下の処理を追加</li></ol>



<div class="hcb_wrap"><pre class="prism line-numbers lang-csharp" data-file="CharCtrl.cs" data-lang="C#"><code>        // 小数点誤差を補正
        float posX = Mathf.Floor(pos.x + 0.5f);
        float posZ = Mathf.Floor(pos.z + 0.5f);
        // 処理対象とするタグの一覧を作成
        string[] tags = new string[] { &quot;Toge&quot; };
        // タグを１つ１つ処理
        for (int i = 0; i &lt; tags.Length; i++)
        {
            // 指定タグのオブジェクト一覧を取得
            GameObject[] objs = GameObject.FindGameObjectsWithTag(tags[i]);
            // オブジェクトを１つ１つ処理
            for (int j = 0; j &lt; objs.Length; j++)
            {
                // 指定位置に存在するオブジェクトを返す
                Vector3 objPos = objs[j].transform.position;
                if (objPos.x == posX && objPos.z == posZ) return objs[j];
            }
        }
</code></pre></div>



<p class="has-medium-font-size"><strong>・スクリプト関数呼び出し</strong></p>



<ol class="wp-block-list"><li>FixedUpdate関数の最後に以下の処理を記述</li></ol>



<div class="hcb_wrap"><pre class="prism line-numbers lang-csharp" data-file="CharCtrl.cs" data-lang="C#"><code>        // 重なったオブジェクトを取得
        GameObject obj = GetObject(transform.position);
        // トゲと重なったら自分とトゲを削除
        if (obj != null && obj.tag == &quot;Toge&quot;)
        {
            Destroy(gameObject);
            Destroy(obj);
        }
</code></pre></div>



<p class="has-medium-font-size"><strong>・スクリプト保存</strong></p>



<ol class="wp-block-list"><li>CTRLを押しながらSキーを押す</li></ol>



<p class="has-medium-font-size"><strong>・Unityに戻ってスクリプトをビルド</strong></p>



<ol class="wp-block-list"><li>Unityエディタのタイトルをクリック</li></ol>



<p class="has-medium-font-size"><strong>・プロジェクト保存</strong></p>



<ol class="wp-block-list"><li>CTRLを押しながらSキーを押す</li></ol>
</div>



<h4 class="wp-block-heading"><span id="toc18">▷動作確認</span></h4>



<div class="wp-block-group is-layout-flow wp-block-group-is-layout-flow">
<p>ヒシガタがトゲと衝突したら両方消えるかどうか、プレビューして確認します。</p>



<figure class="wp-block-image size-full is-resized"><a href="https://d9m.one/wp-content/uploads/2022/07/TandH_012.png"><img decoding="async" src="https://d9m.one/wp-content/uploads/2022/07/TandH_012.png" alt="" class="wp-image-821" width="658" height="475" srcset="https://d9m.one/wp-content/uploads/2022/07/TandH_012.png 877w, https://d9m.one/wp-content/uploads/2022/07/TandH_012-300x217.png 300w, https://d9m.one/wp-content/uploads/2022/07/TandH_012-768x554.png 768w" sizes="(max-width: 658px) 100vw, 658px" /></a><figcaption>動作確認</figcaption></figure>



<p class="has-medium-font-size"><strong>・プレビュー開始</strong></p>



<ol class="wp-block-list"><li>エディタ上中央の「▶」をクリック</li></ol>



<p class="has-medium-font-size"><strong>・動作確認</strong></p>



<ol class="wp-block-list"><li>ヒシガタとトゲがぶつかったら両方消えることを確認</li></ol>



<p class="has-medium-font-size"><strong>・プレビュー終了</strong></p>



<ol class="wp-block-list"><li>エディタ上中央の「▶」をクリック</li></ol>



<p class="has-medium-font-size"><strong>・プレビュー開始</strong></p>



<ol class="wp-block-list"><li>エディタ上中央の「▶」をクリック</li></ol>



<p class="has-medium-font-size"><strong>・プレビュー一時停止</strong></p>



<ol class="wp-block-list"><li>エディタ上中央の「||」をクリック</li></ol>



<p class="has-medium-font-size"><strong>・仮編集</strong></p>



<ol class="wp-block-list"><li>ヒエラルキーの「Toge」をクリック</li><li>インスペクターのTransformにある位置を(0, 0, 2)に設定</li></ol>



<p class="has-medium-font-size"><strong>・プレビュー再開</strong></p>



<ol class="wp-block-list"><li>エディタ上中央の「||」をクリック</li></ol>



<p class="has-medium-font-size"><strong>・動作確認</strong></p>



<ol class="wp-block-list"><li>タマとトゲがぶつかったら両方消えることを確認</li></ol>



<p class="has-medium-font-size"><strong>・プレビュー終了</strong></p>



<ol class="wp-block-list"><li>エディタ上中央の「▶」をクリック</li></ol>
</div>



<h4 class="wp-block-heading"><span id="toc19">▷スクリプト記述例</span></h4>



<div class="wp-block-group is-layout-flow wp-block-group-is-layout-flow">
<p>「トゲと重なったら自分とトゲを削除する」スクリプトの記述例です。</p>



<div class="hcb_wrap"><pre class="prism line-numbers lang-csharp" data-file="CharCtrl.cs" data-lang="C#"><code>using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class CharCtrl : MonoBehaviour
{
    float moveFrame = 30;       // １歩に何フレームかけるか
    float frameCount = 0;       // 経過フレーム数

    // Start is called before the first frame update
    void Start()
    {
        
    }

    // Update is called once per frame
    void Update()
    {
        
    }

    // 物理フレーム更新時に処理
    void FixedUpdate()
    {
        // タグ検索でタマとヒシガタの一覧を取得する
        GameObject[] tamas = GameObject.FindGameObjectsWithTag(&quot;Player&quot;);
        GameObject[] hisis = GameObject.FindGameObjectsWithTag(&quot;Enemy&quot;);

        // １歩分のフレームが経過するまで何もしない
        frameCount++;
        if (frameCount &lt; moveFrame) return;

        // 経過フレーム数を0初期化する
        frameCount = 0;

        // 向いている方向に１メートル進む
        transform.position += transform.forward;

        // ヒシガタとタマが衝突したら両方削除
        if (tamas.Length != 0 && hisis.Length != 0)
        {
            // タマとヒシガタの位置が同じだった場合
            if (tamas[0].transform.position == hisis[0].transform.position)
            {
                // タマとヒシガタを削除
                Destroy(tamas[0]);
                Destroy(hisis[0]);
            }
        }

        // 重なったオブジェクトを取得
        GameObject obj = GetObject(transform.position);
        // トゲと重なったら自分とトゲを削除
        if (obj != null && obj.tag == &quot;Toge&quot;)
        {
            Destroy(gameObject);
            Destroy(obj);
        }
    }

    // 指定位置にあるオブジェクトを取得
    GameObject GetObject(Vector3 pos)
    {
        // 小数点誤差を補正
        float posX = Mathf.Floor(pos.x + 0.5f);
        float posZ = Mathf.Floor(pos.z + 0.5f);
        // 処理対象とするタグの一覧を作成
        string[] tags = new string[] { &quot;Toge&quot; };
        // タグを１つ１つ処理
        for (int i = 0; i &lt; tags.Length; i++)
        {
            // 指定タグのオブジェクト一覧を取得
            GameObject[] objs = GameObject.FindGameObjectsWithTag(tags[i]);
            // オブジェクトを１つ１つ処理
            for (int j = 0; j &lt; objs.Length; j++)
            {
                // 指定位置に存在するオブジェクトを返す
                Vector3 objPos = objs[j].transform.position;
                if (objPos.x == posX && objPos.z == posZ) return objs[j];
            }
        }

        // 指定位置にオブジェクトが無いのでNULLを返す
        return null;
    }
}
</code></pre></div>
</div>



<div style="height:16px" aria-hidden="true" class="wp-block-spacer"></div>
</div>



<p>作成手順を書いた記事です。</p>



<p>　　　<a href="https://d9m.one/proc_tandh/">→紹介</a><br>今▷　<a href="https://d9m.one/proc_tandh1/" type="URL" id="https://d9m.one/proc_tandh1">→１／３　キャラクター作成</a><br>次▷　<a href="https://d9m.one/proc_tandh2/" data-type="post" data-id="954">→２／３　オブジェクト作成</a><br>　　　<a href="https://d9m.one/proc_tandh3/" data-type="post" data-id="958">→３／３　ゲーム仕上げ</a></p>



<p><a href="https://d9m.one/proc_tandh_full/">完全手順</a><br>※紹介と１～３の手順を１ページにまとめています。<br>　読み込みに時間がかかるかも知れません。</p>



<div style="height:16px" aria-hidden="true" class="wp-block-spacer"></div>
<p>投稿 <a href="https://d9m.one/proc_tandh1/">【基本操作】タマあんどヒシガタ～１／３　キャラクター作成【パズル】</a> は <a href="https://d9m.one">だくまたゲーム制作ブログ</a> に最初に表示されました。</p>
]]></content:encoded>
					
					<wfw:commentRss>https://d9m.one/proc_tandh1/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>【基本操作】タマあんどヒシガタ～紹介【パズル】</title>
		<link>https://d9m.one/proc_tandh/</link>
					<comments>https://d9m.one/proc_tandh/#respond</comments>
		
		<dc:creator><![CDATA[だくまた]]></dc:creator>
		<pubDate>Fri, 22 Jul 2022 09:33:24 +0000</pubDate>
				<category><![CDATA[Unity]]></category>
		<category><![CDATA[基本操作]]></category>
		<category><![CDATA[自作ゲーム]]></category>
		<category><![CDATA[チュートリアル]]></category>
		<guid isPermaLink="false">https://d9m.one/?p=943</guid>

					<description><![CDATA[<p>【タマあんどヒシガタ】 タマをゴールまで導くゲームです。 ゲーム画面をクリックするとジャンプ台を押すようにしてタマが動きます。 タマは壁、もしくはジャンプ台にぶつかると停止し、 ヒシガタとトゲにぶつかるとミスとなります。 [&#8230;]</p>
<p>投稿 <a href="https://d9m.one/proc_tandh/">【基本操作】タマあんどヒシガタ～紹介【パズル】</a> は <a href="https://d9m.one">だくまたゲーム制作ブログ</a> に最初に表示されました。</p>
]]></description>
										<content:encoded><![CDATA[
<iframe loading="lazy" src="/game/tandh/index.html" width="450" height="860" scrolling="no" frameborder="0"></iframe>



<pre class="wp-block-preformatted" style="font-size:16px">【タマあんどヒシガタ】
タマをゴールまで導くゲームです。

ゲーム画面をクリックするとジャンプ台を押すようにしてタマが動きます。
タマは壁、もしくはジャンプ台にぶつかると停止し、
ヒシガタとトゲにぶつかるとミスとなります。
ヒシガタはタマと同じようにジャンプ台を利用して動き、トゲとぶつかると両方消滅します。

トゲとヒシガタにぶつからないよう、タマをゴールまで導いてください。


身に付くこと　：基本操作
対象　　　　　：初心者、Unityに初めて触る方
使用バージョン：Unity 2021.3
時間　　　　　：1.5時間</pre>



<p>作成手順を書いた記事です。</p>



<p>　　　<a href="https://d9m.one/proc_tandh/">→紹介</a><br>次▷　<a href="https://d9m.one/proc_tandh1/">→１／３　キャラクター作成</a><br>　　　<a href="https://d9m.one/proc_tandh2/" type="post">→２／３　オブジェクト作成</a><br>　　　<a href="https://d9m.one/proc_tandh3/">→３／３　ゲーム仕上げ</a></p>



<p><a href="https://d9m.one/proc_tandh_full/">完全手順</a><br>※紹介と１～３の手順を１ページにまとめています。<br>　読み込みに時間がかかるかも知れません。</p>
<p>投稿 <a href="https://d9m.one/proc_tandh/">【基本操作】タマあんどヒシガタ～紹介【パズル】</a> は <a href="https://d9m.one">だくまたゲーム制作ブログ</a> に最初に表示されました。</p>
]]></content:encoded>
					
					<wfw:commentRss>https://d9m.one/proc_tandh/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>【基本操作】タマあんどヒシガタ～完全手順【パズル】</title>
		<link>https://d9m.one/proc_tandh_full/</link>
					<comments>https://d9m.one/proc_tandh_full/#respond</comments>
		
		<dc:creator><![CDATA[だくまた]]></dc:creator>
		<pubDate>Fri, 22 Jul 2022 09:32:48 +0000</pubDate>
				<category><![CDATA[Unity]]></category>
		<category><![CDATA[基本操作]]></category>
		<category><![CDATA[自作ゲーム]]></category>
		<category><![CDATA[チュートリアル]]></category>
		<guid isPermaLink="false">https://d9m.one/?p=648</guid>

					<description><![CDATA[<p>【タマあんどヒシガタ】 タマをゴールまで導くゲームです。 ゲーム画面をクリックするとジャンプ台を押すようにしてタマが動きます。 タマは壁、もしくはジャンプ台にぶつかると停止し、 ヒシガタとトゲにぶつかるとミスとなります。 [&#8230;]</p>
<p>投稿 <a href="https://d9m.one/proc_tandh_full/">【基本操作】タマあんどヒシガタ～完全手順【パズル】</a> は <a href="https://d9m.one">だくまたゲーム制作ブログ</a> に最初に表示されました。</p>
]]></description>
										<content:encoded><![CDATA[
<pre class="wp-block-preformatted" style="font-size:16px">【タマあんどヒシガタ】
タマをゴールまで導くゲームです。

ゲーム画面をクリックするとジャンプ台を押すようにしてタマが動きます。
タマは壁、もしくはジャンプ台にぶつかると停止し、
ヒシガタとトゲにぶつかるとミスとなります。
ヒシガタはタマと同じようにジャンプ台を利用して動き、トゲとぶつかると両方消滅します。

トゲとヒシガタにぶつからないよう、タマをゴールまで導いてください。


身に付くこと　：基本操作
対象　　　　　：初心者、Unityに初めて触る方
使用バージョン：Unity 2021.3
時間　　　　　：1.5時間</pre>



<iframe loading="lazy" src="/game/tandh/index.html" width="450" height="860" scrolling="no" frameborder="0"></iframe>




  <div id="toc" class="toc tnt-number toc-center tnt-number border-element"><input type="checkbox" class="toc-checkbox" id="toc-checkbox-10" checked><label class="toc-title" for="toc-checkbox-10">目次</label>
    <div class="toc-content">
    <ol class="toc-list open"><li><a href="#toc1" tabindex="0">■キャラクター作成</a><ol><li><a href="#toc2" tabindex="0">●タマ作成</a><ol><li><a href="#toc3" tabindex="0">▷タマ作成</a></li><li><a href="#toc4" tabindex="0">▷タマ制御</a></li><li><a href="#toc5" tabindex="0">▷タマ認識</a></li><li><a href="#toc6" tabindex="0">▷動作確認</a></li><li><a href="#toc7" tabindex="0">▷スクリプト記述例</a></li></ol></li><li><a href="#toc8" tabindex="0">●ヒシガタ作成</a><ol><li><a href="#toc9" tabindex="0">▷ヒシガタ作成</a></li><li><a href="#toc10" tabindex="0">▷ヒシガタ階層化</a></li><li><a href="#toc11" tabindex="0">▷ヒシガタ認識</a></li><li><a href="#toc12" tabindex="0">▷ヒシガタ制御</a></li><li><a href="#toc13" tabindex="0">▷動作確認</a></li><li><a href="#toc14" tabindex="0">▷スクリプト記述例</a></li></ol></li><li><a href="#toc15" tabindex="0">●トゲ作成</a><ol><li><a href="#toc16" tabindex="0">▷トゲ作成</a></li><li><a href="#toc17" tabindex="0">▷トゲ認識</a></li><li><a href="#toc18" tabindex="0">▷トゲ制御</a></li><li><a href="#toc19" tabindex="0">▷動作確認</a></li><li><a href="#toc20" tabindex="0">▷スクリプト記述例</a></li></ol></li></ol></li><li><a href="#toc21" tabindex="0">■オブジェクト作成</a><ol><li><a href="#toc22" tabindex="0">●床作成</a><ol><li><a href="#toc23" tabindex="0">▷床作成</a></li></ol></li><li><a href="#toc24" tabindex="0">●壁作成</a><ol><li><a href="#toc25" tabindex="0">▷壁作成</a></li><li><a href="#toc26" tabindex="0">▷壁認識</a></li><li><a href="#toc27" tabindex="0">▷壁衝突</a></li><li><a href="#toc28" tabindex="0">▷動作確認</a></li></ol></li><li><a href="#toc29" tabindex="0">●ジャンプ台作成</a><ol><li><a href="#toc30" tabindex="0">▷ジャンプ台作成</a></li><li><a href="#toc31" tabindex="0">▷ジャンプ台認識</a></li><li><a href="#toc32" tabindex="0">▷ジャンプ台制御</a></li><li><a href="#toc33" tabindex="0">▷動作確認</a></li><li><a href="#toc34" tabindex="0">▷スクリプト記述例</a></li></ol></li><li><a href="#toc35" tabindex="0">●ゴール作成</a><ol><li><a href="#toc36" tabindex="0">▷ゴール作成</a></li><li><a href="#toc37" tabindex="0">▷ゴール認識</a></li><li><a href="#toc38" tabindex="0">▷ゴール制御</a></li><li><a href="#toc39" tabindex="0">▷動作確認</a></li><li><a href="#toc40" tabindex="0">▷スクリプト記述例</a></li></ol></li></ol></li><li><a href="#toc41" tabindex="0">■ゲーム仕上げ</a><ol><li><a href="#toc42" tabindex="0">●ステージ作成</a><ol><li><a href="#toc43" tabindex="0">▷カメラ設定</a></li><li><a href="#toc44" tabindex="0">▷プレハブ化</a></li><li><a href="#toc45" tabindex="0">▷単一オブジェクト配置</a></li><li><a href="#toc46" tabindex="0">▷トゲ配置</a></li><li><a href="#toc47" tabindex="0">▷ジャンプ台配置</a></li><li><a href="#toc48" tabindex="0">▷壁配置</a></li></ol></li><li><a href="#toc49" tabindex="0">●ミスUI作成</a><ol><li><a href="#toc50" tabindex="0">▷ミスUI作成</a></li><li><a href="#toc51" tabindex="0">▷ミス制御</a></li><li><a href="#toc52" tabindex="0">▷動作確認</a></li></ol></li><li><a href="#toc53" tabindex="0">●クリアUI作成</a><ol><li><a href="#toc54" tabindex="0">▷クリアUI作成</a></li><li><a href="#toc55" tabindex="0">▷クリア制御</a></li><li><a href="#toc56" tabindex="0">▷動作確認</a></li></ol></li></ol></li></ol>
    </div>
  </div>

<h2 class="has-text-align-left has-background has-large-font-size wp-block-heading" style="background-color:#f1e0f8;font-style:normal;font-weight:700"><span id="toc1">■キャラクター作成</span></h2>



<div style="height:16px" aria-hidden="true" class="wp-block-spacer"></div>



<h3 class="has-background has-medium-font-size wp-block-heading" style="background-color:#e5f7fd"><span id="toc2">●タマ作成</span></h3>



<div style="height:16px" aria-hidden="true" class="wp-block-spacer"></div>



<div class="wp-block-group is-layout-flow wp-block-group-is-layout-flow">
<p>最初にプレイヤーとして動かすタマを作成します。<br>タマの隣にジャンプ台がある時に画面をクリックすると、ジャンプ台に押したように動き出します。<br>まずは単純に、いきなり進み続けるように作成します。</p>



<h4 class="wp-block-heading"><span id="toc3">▷タマ作成</span></h4>



<div class="wp-block-group is-layout-flow wp-block-group-is-layout-flow">
<p>球を作成してTransformをリセットし、青色設定したマテリアルを割り当てます。</p>



<figure class="wp-block-image size-full is-resized"><a href="https://d9m.one/wp-content/uploads/2022/07/TandH_000.png"><img decoding="async" src="https://d9m.one/wp-content/uploads/2022/07/TandH_000.png" alt="" class="wp-image-807" width="658" height="475" srcset="https://d9m.one/wp-content/uploads/2022/07/TandH_000.png 877w, https://d9m.one/wp-content/uploads/2022/07/TandH_000-300x217.png 300w, https://d9m.one/wp-content/uploads/2022/07/TandH_000-768x554.png 768w" sizes="(max-width: 658px) 100vw, 658px" /></a><figcaption>タマ作成</figcaption></figure>



<p class="has-medium-font-size"><strong>・球作成</strong></p>



<ol class="wp-block-list"><li>ヒエラルキー左上の「＋」をクリック</li><li>「3Dオブジェクト＞スフィア」をクリック</li><li>「Tama」と入力し、ENTERキーを押す</li></ol>



<p class="has-medium-font-size"><strong>・位置、回転、スケールリセット</strong></p>



<ol class="wp-block-list"><li>インスペクターのTransformにある縦の三点リーダーをクリック</li><li>リセットをクリック</li></ol>



<p class="has-medium-font-size"><strong>・マテリアル作成</strong></p>



<ol class="wp-block-list"><li>プロジェクトの「Assets」を右クリックし、「作成＞マテリアル」をクリック</li><li>「matTama」と入力し、ENTERキーを押す</li></ol>



<p class="has-medium-font-size"><strong>・マテリアル色設定</strong></p>



<ol class="wp-block-list"><li>インスペクターの「Main Maps&gt;アルベド＞カラーバー」をクリックし、色ダイアログの16進数を「0000FF」に設定</li><li>色ダイアログの右上にある「×」をクリック</li></ol>



<p class="has-medium-font-size"><strong>・マテリアル割り当て</strong></p>



<ol class="wp-block-list"><li>プロジェクトの「matTama」をヒエラルキーの「Tama」にドラッグ＆ドロップ</li></ol>
</div>



<h4 class="wp-block-heading"><span id="toc4">▷タマ制御</span></h4>



<div class="wp-block-group is-layout-flow wp-block-group-is-layout-flow">
<p>スクリプトを作成してタマに割り当て、「タマを30フレームに1メートルの速さで動く」ようにスクリプトを記述します。</p>



<figure class="wp-block-image size-full is-resized"><a href="https://d9m.one/wp-content/uploads/2022/07/TandH_001.png"><img decoding="async" src="https://d9m.one/wp-content/uploads/2022/07/TandH_001.png" alt="" class="wp-image-808" width="658" height="475" srcset="https://d9m.one/wp-content/uploads/2022/07/TandH_001.png 877w, https://d9m.one/wp-content/uploads/2022/07/TandH_001-300x217.png 300w, https://d9m.one/wp-content/uploads/2022/07/TandH_001-768x554.png 768w" sizes="(max-width: 658px) 100vw, 658px" /></a><figcaption>タマ制御</figcaption></figure>



<p class="has-medium-font-size"><strong>・スクリプト作成</strong></p>



<ol class="wp-block-list"><li>プロジェクトの「Assets」を右クリックし、「作成＞C# スクリプト」をクリック</li><li>「CharCtrl」と入力し、ENTERキーを押す</li></ol>



<p class="has-medium-font-size"><strong>・スクリプト割り当て</strong></p>



<ol class="wp-block-list"><li>プロジェクトの「Assets&gt;CharCtrl」をヒエラルキーの「Tama」にドラッグ＆ドロップ</li></ol>



<p class="has-medium-font-size">・<strong>スクリプト</strong>編集開始</p>



<ol class="wp-block-list"><li>プロジェクトの「Assets&gt;CharCtrl」をダブルクリック</li></ol>



<p class="has-medium-font-size"><strong>・スクリプト変数定義</strong></p>



<ol class="wp-block-list"><li>クラス定義内の先頭に以下の変数を追加</li></ol>



<div class="hcb_wrap"><pre class="prism line-numbers lang-csharp" data-file="CharCtrl.cs" data-lang="C#"><code>    float moveFrame = 30;       // １歩に何フレームかけるか
    float frameCount = 0;       // 経過フレーム数
</code></pre></div>



<p class="has-medium-font-size"><strong>・スクリプト関数定義</strong></p>



<ol class="wp-block-list"><li>クラス定義内の最後に以下の関数を追加</li></ol>



<div class="hcb_wrap"><pre class="prism line-numbers lang-csharp" data-file="CharCtrl.cs" data-lang="C#"><code>    // 物理フレーム更新時に処理
    void FixedUpdate()
    {
    }
</code></pre></div>



<p class="has-medium-font-size">・<strong>スクリプト処理</strong></p>



<ol class="wp-block-list" id="block-df2c71c8-85d2-454d-ba7a-555e235c2226"><li>FixedFrameに以下の処理を記述</li></ol>



<div class="hcb_wrap"><pre class="prism line-numbers lang-csharp" data-file="CharCtrl.cs" data-lang="C#"><code>        // １歩分のフレームが経過するまで何もしない
        frameCount++;
        if (frameCount &lt; moveFrame) return;

        // 経過フレーム数を0初期化する
        frameCount = 0;

        // 向いている方向に１メートル進む
        transform.position += transform.forward;
</code></pre></div>



<p class="has-medium-font-size"><strong>・スクリプト保存</strong></p>



<ol class="wp-block-list"><li>CTRLを押しながらSキーを押す</li></ol>



<p class="has-medium-font-size"><strong>・Unityに戻ってスクリプトをビルド</strong></p>



<ol class="wp-block-list" id="block-d832c413-6256-49d3-b625-25f4086a75c5"><li>Unityエディタのタイトルをクリック</li></ol>
</div>



<h4 class="wp-block-heading"><span id="toc5">▷タマ認識</span></h4>



<div class="wp-block-group is-layout-flow wp-block-group-is-layout-flow">
<p>スクリプトでタマを認識させるため、タグ「Player」をタマに割り当てます。</p>



<figure class="wp-block-image size-full is-resized"><a href="https://d9m.one/wp-content/uploads/2022/07/TandH_002.png"><img decoding="async" src="https://d9m.one/wp-content/uploads/2022/07/TandH_002.png" alt="" class="wp-image-809" width="658" height="475" srcset="https://d9m.one/wp-content/uploads/2022/07/TandH_002.png 877w, https://d9m.one/wp-content/uploads/2022/07/TandH_002-300x217.png 300w, https://d9m.one/wp-content/uploads/2022/07/TandH_002-768x554.png 768w" sizes="(max-width: 658px) 100vw, 658px" /></a><figcaption>タマ認識</figcaption></figure>



<p class="has-medium-font-size"><strong>・タグ割り当て</strong></p>



<ol class="wp-block-list" id="block-d832c413-6256-49d3-b625-25f4086a75c5"><li>ヒエラルキーの「Tama」をクリック</li><li>インスペクター上部のタグドロップダウンをクリックし、「Player」をクリック</li></ol>



<p class="has-medium-font-size"><strong><strong>・プロジェクト保存</strong></strong></p>



<ol class="wp-block-list"><li>CTRLを押しながらSキーを押す</li></ol>
</div>



<h4 class="wp-block-heading"><span id="toc6">▷動作確認</span></h4>



<div class="wp-block-group is-layout-flow wp-block-group-is-layout-flow">
<p>タマが期待通り動くかどうか、プレビューして確認します。</p>



<figure class="wp-block-image size-full is-resized"><a href="https://d9m.one/wp-content/uploads/2022/07/TandH_003.png"><img decoding="async" src="https://d9m.one/wp-content/uploads/2022/07/TandH_003.png" alt="" class="wp-image-810" width="658" height="475" srcset="https://d9m.one/wp-content/uploads/2022/07/TandH_003.png 877w, https://d9m.one/wp-content/uploads/2022/07/TandH_003-300x217.png 300w, https://d9m.one/wp-content/uploads/2022/07/TandH_003-768x554.png 768w" sizes="(max-width: 658px) 100vw, 658px" /></a><figcaption>動作確認</figcaption></figure>



<p class="has-medium-font-size"><strong>・プレビュー</strong>開始</p>



<ol class="wp-block-list"><li>エディタ上中央の「▶」をクリック</li></ol>



<p class="has-medium-font-size"><strong>・動作確認</strong></p>



<ol class="wp-block-list"><li>奥に向かって１メートルごとに進むことを確認</li></ol>



<p class="has-medium-font-size"><strong>・プレビュー</strong>終了</p>



<ol class="wp-block-list"><li>エディタ上中央の「▶」をクリック</li></ol>
</div>



<h4 class="wp-block-heading"><span id="toc7">▷スクリプト記述例</span></h4>



<div class="wp-block-group is-layout-flow wp-block-group-is-layout-flow">
<p>「タマを30フレームに1メートルの速さで動く」スクリプトの記述例です。</p>



<div class="hcb_wrap"><pre class="prism line-numbers lang-csharp" data-file="CharCtrl.cs" data-lang="C#"><code>using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class CharCtrl : MonoBehaviour
{
    float moveFrame = 30;       // １歩に何フレームかけるか
    float frameCount = 0;       // 経過フレーム数

    // Start is called before the first frame update
    void Start()
    {
        
    }

    // Update is called once per frame
    void Update()
    {
        
    }

    // 物理フレーム更新時に処理
    void FixedUpdate()
    {
        // １歩分のフレームが経過するまで何もしない
        frameCount++;
        if (frameCount &lt; moveFrame) return;

        // 経過フレーム数を0初期化する
        frameCount = 0;

        // 向いている方向に１メートル進む
        transform.position += transform.forward;
    }
}
</code></pre></div>
</div>



<div style="height:16px" aria-hidden="true" class="wp-block-spacer"></div>
</div>



<h3 class="has-background has-medium-font-size wp-block-heading" style="background-color:#e5f7fd"><span id="toc8">●ヒシガタ作成</span></h3>



<div class="wp-block-group is-layout-flow wp-block-group-is-layout-flow">
<div style="height:16px" aria-hidden="true" class="wp-block-spacer"></div>



<p>次に、同じように動くキャラクター「ヒシガタ」を作成します。<br>タマと衝突すると両方とも消滅します。</p>



<h4 class="wp-block-heading"><span id="toc9">▷ヒシガタ作成</span></h4>



<div class="wp-block-group is-layout-flow wp-block-group-is-layout-flow">
<p>箱を作成してTransformを「位置(0, 0, 0)、回転(0, 45, 0)、スケール(0.7, 1, 0.7)」とし、赤色設定したマテリアルを割り当てます。</p>



<figure class="wp-block-image size-full is-resized"><a href="https://d9m.one/wp-content/uploads/2022/07/TandH_004.png"><img decoding="async" src="https://d9m.one/wp-content/uploads/2022/07/TandH_004.png" alt="" class="wp-image-812" width="658" height="475" srcset="https://d9m.one/wp-content/uploads/2022/07/TandH_004.png 877w, https://d9m.one/wp-content/uploads/2022/07/TandH_004-300x217.png 300w, https://d9m.one/wp-content/uploads/2022/07/TandH_004-768x554.png 768w" sizes="(max-width: 658px) 100vw, 658px" /></a><figcaption>ヒシガタ作成</figcaption></figure>



<p class="has-medium-font-size"><strong>・箱作成</strong></p>



<ol class="wp-block-list"><li>ヒエラルキー左上の「＋」をクリック</li><li>「3Dオブジェクト＞キューブ」をクリック</li></ol>



<p class="has-medium-font-size"><strong>・位置、回転、スケール設定</strong></p>



<ol class="wp-block-list"><li>インスペクターのTransformにある位置を(0, 0, 0)とする</li><li>インスペクターのTransformにある回転を(0, 45, 0)とする</li><li>インスペクターのTransformにあるスケールを(0.7, 1, 0.7)とする</li></ol>



<p class="has-medium-font-size"><strong>・マテリアル作成</strong></p>



<ol class="wp-block-list"><li>プロジェクトの「Assets」を右クリックし、「作成＞マテリアル」をクリック</li><li>「matHisi」と入力し、ENTERキーを押す</li></ol>



<p class="has-medium-font-size"><strong>・マテリアル色設定</strong></p>



<ol class="wp-block-list"><li>インスペクターの「MainMaps&gt;アルベド＞カラーバー」をクリックし、色ダイアログの16進数を「FF0000」に設定</li><li>色ダイアログの右上にある「×」をクリック</li></ol>



<p class="has-medium-font-size"><strong>・マテリアル割り当て</strong></p>



<ol class="wp-block-list"><li>プロジェクトの「matHisi」をヒエラルキーの「Cube」にドラッグ＆ドロップ</li></ol>
</div>



<h4 class="wp-block-heading"><span id="toc10">▷ヒシガタ階層化</span></h4>



<div class="wp-block-group is-layout-flow wp-block-group-is-layout-flow">
<p>空オブジェクトを作成してTransformを「位置(1, 0, 0)、回転(0, 270, 0)、スケール(1, 1, 1)」とし、赤色の箱を子供とします。</p>



<figure class="wp-block-image size-full is-resized"><a href="https://d9m.one/wp-content/uploads/2022/07/TandH_005.png"><img decoding="async" src="https://d9m.one/wp-content/uploads/2022/07/TandH_005.png" alt="" class="wp-image-813" width="658" height="475" srcset="https://d9m.one/wp-content/uploads/2022/07/TandH_005.png 877w, https://d9m.one/wp-content/uploads/2022/07/TandH_005-300x217.png 300w, https://d9m.one/wp-content/uploads/2022/07/TandH_005-768x554.png 768w" sizes="(max-width: 658px) 100vw, 658px" /></a><figcaption>ヒシガタ階層化</figcaption></figure>



<p class="has-medium-font-size"><strong>・空オブジェクト作成</strong></p>



<ol class="wp-block-list"><li>ヒエラルキー左上の「＋」をクリック</li><li>「空のオブジェクトを作成」をクリック</li><li>「Hisi」と入力し、ENTERキーを押す</li></ol>



<p class="has-medium-font-size"><strong>・階層設定</strong></p>



<ol class="wp-block-list"><li>ヒエラルキーの「Cube」をヒエラルキーの「Hisi」にドラッグ＆ドロップ</li></ol>



<p class="has-medium-font-size"><strong>・位置、回転、スケール設定</strong></p>



<ol class="wp-block-list"><li>ヒエラルキーの「Hisi」をクリック</li><li>インスペクターのTransformにある位置を(3, 0, 3)とする</li><li>インスペクターのTransformにある回転を(0, 270, 0)とする</li><li>インスペクターのTransformにあるスケールを(1, 1, 1)とする</li></ol>
</div>



<h4 class="wp-block-heading"><span id="toc11">▷ヒシガタ認識</span></h4>



<div class="wp-block-group is-layout-flow wp-block-group-is-layout-flow">
<p>タグ「Enemy」を作成し、ヒシガタに割り当てます。</p>



<figure class="wp-block-image size-full is-resized"><a href="https://d9m.one/wp-content/uploads/2022/07/TandH_006.png"><img decoding="async" src="https://d9m.one/wp-content/uploads/2022/07/TandH_006.png" alt="" class="wp-image-814" width="658" height="475" srcset="https://d9m.one/wp-content/uploads/2022/07/TandH_006.png 877w, https://d9m.one/wp-content/uploads/2022/07/TandH_006-300x217.png 300w, https://d9m.one/wp-content/uploads/2022/07/TandH_006-768x554.png 768w" sizes="(max-width: 658px) 100vw, 658px" /></a><figcaption>ヒシガタ認識</figcaption></figure>



<p class="has-medium-font-size"><strong>・タグ作成</strong></p>



<ol class="wp-block-list" id="block-d832c413-6256-49d3-b625-25f4086a75c5"><li>ヒエラルキーの「Hisi」をクリック</li><li>インスペクター上部のタグドロップダウンをクリックし、「タグを追加&#8230;」をクリック</li><li>インスペクター「Tag &amp; Layers」にあるタグ欄右下の「＋」をクリック</li><li>「Enemy」と入力してENTERを押す</li></ol>



<p class="has-medium-font-size"><strong>・タグ割り当て</strong></p>



<ol class="wp-block-list" id="block-3f34234f-49e3-4ace-a1a6-ad25622ab28e"><li>ヒエラルキーの「Hisi」をクリック</li><li>インスペクターのタグドロップダウンをクリックし、「Enemy」をクリック</li></ol>
</div>



<h4 class="wp-block-heading"><span id="toc12">▷ヒシガタ制御</span></h4>



<div class="wp-block-group is-layout-flow wp-block-group-is-layout-flow">
<p>ヒシガタにCharCtrlを割り当て、CharCtrlを「タマとヒシガタが衝突したら両方削除する」ように修正します。</p>



<figure class="wp-block-image size-full is-resized"><a href="https://d9m.one/wp-content/uploads/2022/07/TandH_007.png"><img decoding="async" src="https://d9m.one/wp-content/uploads/2022/07/TandH_007.png" alt="" class="wp-image-815" width="658" height="475" srcset="https://d9m.one/wp-content/uploads/2022/07/TandH_007.png 877w, https://d9m.one/wp-content/uploads/2022/07/TandH_007-300x217.png 300w, https://d9m.one/wp-content/uploads/2022/07/TandH_007-768x554.png 768w" sizes="(max-width: 658px) 100vw, 658px" /></a><figcaption>ヒシガタ制御</figcaption></figure>



<p class="has-medium-font-size"><strong>・スクリプト割り当て</strong></p>



<ol class="wp-block-list"><li>プロジェクトの「Assets&gt;CharCtrl」をヒエラルキーの「Hisi」にドラッグ＆ドロップ</li></ol>



<p class="has-medium-font-size"><strong>・スクリプト編集開始</strong></p>



<ol class="wp-block-list"><li>プロジェクトの「Assets&gt;CharCtrl」をダブルクリック</li></ol>



<p class="has-medium-font-size"><strong>・タグでオブジェクトを検索</strong></p>



<ol class="wp-block-list"><li>FixedUpdate関数の処理先頭に「タグ検索でタマとヒシガタの一覧を取得する」処理を追加</li></ol>



<div class="hcb_wrap"><pre class="prism line-numbers lang-csharp" data-file="CharCtrl.cs" data-lang="C#"><code>        // タグ検索でタマとヒシガタの一覧を取得する
        GameObject[] tamas = GameObject.FindGameObjectsWithTag(&quot;Player&quot;);
        GameObject[] hisis = GameObject.FindGameObjectsWithTag(&quot;Enemy&quot;);
</code></pre></div>



<p class="has-medium-font-size"><strong>・衝突時にオブジェクトを削除</strong></p>



<ol class="wp-block-list"><li>移動処理の後に「ヒシガタとタマが衝突したら両方削除」する処理を追加</li></ol>



<div class="hcb_wrap"><pre class="prism line-numbers lang-csharp" data-file="CharCtrl.cs" data-lang="C#"><code>        // ヒシガタとタマが衝突したら両方削除
        if (tamas.Length != 0 && hisis.Length != 0)
        {
            // タマとヒシガタの位置が同じだった場合
            if (tamas[0].transform.position == hisis[0].transform.position)
            {
                // タマとヒシガタを削除
                Destroy(tamas[0]);
                Destroy(hisis[0]);
            }
        }
</code></pre></div>



<p class="has-medium-font-size"><strong>・スクリプト保存</strong></p>



<ol class="wp-block-list"><li>CTRLを押しながらSキーを押す</li></ol>



<p class="has-medium-font-size"><strong>・Unityに戻ってスクリプトをビルド</strong></p>



<ol class="wp-block-list" id="block-d832c413-6256-49d3-b625-25f4086a75c5"><li>Unityエディタのタイトルをクリック</li></ol>



<p class="has-medium-font-size"><strong>・プロジェクト保存</strong></p>



<ol class="wp-block-list"><li>CTRLを押しながらSキーを押す</li></ol>
</div>



<h4 class="wp-block-heading"><span id="toc13">▷動作確認</span></h4>



<div class="wp-block-group is-layout-flow wp-block-group-is-layout-flow">
<p>ヒシガタが期待通り動き、タマと衝突したら両方消えるかどうか、プレビューして確認します。</p>



<figure class="wp-block-image size-full is-resized"><a href="https://d9m.one/wp-content/uploads/2022/07/TandH_008.png"><img decoding="async" src="https://d9m.one/wp-content/uploads/2022/07/TandH_008.png" alt="" class="wp-image-816" width="658" height="475" srcset="https://d9m.one/wp-content/uploads/2022/07/TandH_008.png 877w, https://d9m.one/wp-content/uploads/2022/07/TandH_008-300x217.png 300w, https://d9m.one/wp-content/uploads/2022/07/TandH_008-768x554.png 768w" sizes="(max-width: 658px) 100vw, 658px" /></a><figcaption>動作確認</figcaption></figure>



<p class="has-medium-font-size"><strong>・プレビュー</strong>開始</p>



<ol class="wp-block-list"><li>エディタ上中央の「▶」をクリック</li></ol>



<p class="has-medium-font-size"><strong>・動作確認</strong></p>



<ol class="wp-block-list"><li>ヒシガタが左奥に向かって進むことを確認</li><li>タマとヒシガタがぶつかったら両方消えることを確認</li></ol>



<p class="has-medium-font-size"><strong>・プレビュー終了</strong></p>



<ol class="wp-block-list"><li>エディタ上中央の「▶」をクリック</li></ol>
</div>



<h4 class="wp-block-heading"><span id="toc14">▷スクリプト記述例</span></h4>



<div class="wp-block-group is-layout-flow wp-block-group-is-layout-flow">
<p>「タマとヒシガタが衝突したら両方削除する」スクリプトの記述例です。</p>



<div class="hcb_wrap"><pre class="prism line-numbers lang-csharp" data-file="CharCtrl.cs" data-lang="C#"><code>using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class CharCtrl : MonoBehaviour
{
    float moveFrame = 30;       // １歩に何フレームかけるか
    float frameCount = 0;       // 経過フレーム数

    // Start is called before the first frame update
    void Start()
    {
        
    }

    // Update is called once per frame
    void Update()
    {
        
    }

    // 物理フレーム更新時に処理
    void FixedUpdate()
    {
        // タグ検索でタマとヒシガタの一覧を取得する
        GameObject[] tamas = GameObject.FindGameObjectsWithTag(&quot;Player&quot;);
        GameObject[] hisis = GameObject.FindGameObjectsWithTag(&quot;Enemy&quot;);

        // １歩分のフレームが経過するまで何もしない
        frameCount++;
        if (frameCount &lt; moveFrame) return;

        // 経過フレーム数を0初期化する
        frameCount = 0;

        // 向いている方向に１メートル進む
        transform.position += transform.forward;

        // ヒシガタとタマが衝突したら両方削除
        if (tamas.Length != 0 && hisis.Length != 0)
        {
            // タマとヒシガタの位置が同じだった場合
            if (tamas[0].transform.position == hisis[0].transform.position)
            {
                // タマとヒシガタを削除
                Destroy(tamas[0]);
                Destroy(hisis[0]);
            }
        }
    }
}
</code></pre></div>
</div>



<div style="height:16px" aria-hidden="true" class="wp-block-spacer"></div>
</div>



<h3 class="has-background has-medium-font-size wp-block-heading" style="background-color:#e5f7fd"><span id="toc15">●トゲ作成</span></h3>



<div class="wp-block-group is-layout-flow wp-block-group-is-layout-flow">
<div style="height:16px" aria-hidden="true" class="wp-block-spacer"></div>



<p>動かないヒシガタである「トゲ」を作成します。<br>タマやヒシガタが衝突するとトゲとともに消滅します。</p>



<h4 class="wp-block-heading"><span id="toc16">▷トゲ作成</span></h4>



<div class="wp-block-group is-layout-flow wp-block-group-is-layout-flow">
<p>同じ構成なので、ヒシガタをコピーして利用します。<br>名前を変更して位置を(1, 0, 3)とし、色を紫に変更します。</p>



<figure class="wp-block-image size-full is-resized"><a href="https://d9m.one/wp-content/uploads/2022/07/TandH_009.png"><img decoding="async" src="https://d9m.one/wp-content/uploads/2022/07/TandH_009.png" alt="" class="wp-image-817" width="658" height="475" srcset="https://d9m.one/wp-content/uploads/2022/07/TandH_009.png 877w, https://d9m.one/wp-content/uploads/2022/07/TandH_009-300x217.png 300w, https://d9m.one/wp-content/uploads/2022/07/TandH_009-768x554.png 768w" sizes="(max-width: 658px) 100vw, 658px" /></a><figcaption>トゲ作成</figcaption></figure>



<p class="has-medium-font-size"><strong>・オブジェクト複製</strong></p>



<ol class="wp-block-list"><li>ヒエラルキーの「Hisi」をクリック</li><li>CTRLを押しながらDキーを押す</li></ol>



<p class="has-medium-font-size"><strong>・オブジェクト名変更</strong></p>



<ol class="wp-block-list"><li>F2キーを押す</li><li>「Toge」と入力し、ENTERキーを押す</li></ol>



<p class="has-medium-font-size"><strong>・位置設定</strong></p>



<ol class="wp-block-list"><li>インスペクターのTransformにある位置を(1, 0, 3)に設定</li></ol>



<p class="has-medium-font-size"><strong>・アセット複製</strong></p>



<ol class="wp-block-list"><li>プロジェクトの「Assets&gt;matHisi」をクリック</li><li>CTRLを押しながらDキーを押す</li></ol>



<p class="has-medium-font-size">・<strong>アセット名変更</strong></p>



<ol class="wp-block-list"><li>F2キーを押す</li><li>「matToge」を入力し、ENTERキーを押す</li></ol>



<p class="has-medium-font-size"><strong>・マテリアル色設定</strong></p>



<ol class="wp-block-list"><li>インスペクターの「Main Maps&gt;アルベド＞カラーバー」をクリックし、色ダイアログの16進数を「FF00FF」に設定</li><li>色ダイアログの右上にある「×」をクリック</li></ol>



<p class="has-medium-font-size"><strong>・マテリアル割り当て</strong></p>



<ol class="wp-block-list"><li>ヒエラルキーの「Toge」左にある「▶」をクリック</li><li>プロジェクトの「Assets&gt;matToge」をヒエラルキーの「Toge&gt;Cube」にドラッグ＆ドロップ</li></ol>
</div>



<h4 class="wp-block-heading"><span id="toc17">▷トゲ認識</span></h4>



<div class="wp-block-group is-layout-flow wp-block-group-is-layout-flow">
<p>タグ「Toge」を作成し、トゲに割り当てます。</p>



<figure class="wp-block-image size-full is-resized"><a href="https://d9m.one/wp-content/uploads/2022/07/TandH_010.png"><img decoding="async" src="https://d9m.one/wp-content/uploads/2022/07/TandH_010.png" alt="" class="wp-image-819" width="658" height="475" srcset="https://d9m.one/wp-content/uploads/2022/07/TandH_010.png 877w, https://d9m.one/wp-content/uploads/2022/07/TandH_010-300x217.png 300w, https://d9m.one/wp-content/uploads/2022/07/TandH_010-768x554.png 768w" sizes="(max-width: 658px) 100vw, 658px" /></a><figcaption>トゲ認識</figcaption></figure>



<p class="has-medium-font-size"><strong>・タグ作成</strong></p>



<ol class="wp-block-list"><li>ヒエラルキーの「Toge」をクリック</li><li>インスペクターのタグドロップダウンをクリックし、「タグを追加&#8230;」をクリック</li><li>インスペクター「Tag &amp; Layers」にあるタグ欄右下の「＋」をクリック</li><li>「Toge」と入力してENTERを押す</li></ol>



<p class="has-medium-font-size"><strong>・タグ割り当て</strong></p>



<ol class="wp-block-list"><li>ヒエラルキーの「Toge」をクリック</li><li>インスペクターのタグドロップダウンをクリックし、「Toge」をクリック</li></ol>
</div>



<h4 class="wp-block-heading"><span id="toc18">▷トゲ制御</span></h4>



<div class="wp-block-group is-layout-flow wp-block-group-is-layout-flow">
<p>トゲは動かないのでCharCtrlスクリプトを外します。<br>「自分（タマかヒシガタ）がトゲと衝突した時に両方消える」ようにCharCtrlを修正します。<br>結果、トゲとタマ、もしくはトゲとヒシガタが衝突した時に両方が消えるようになります。</p>



<figure class="wp-block-image size-full is-resized"><a href="https://d9m.one/wp-content/uploads/2022/07/TandH_011.png"><img decoding="async" src="https://d9m.one/wp-content/uploads/2022/07/TandH_011.png" alt="" class="wp-image-820" width="658" height="475" srcset="https://d9m.one/wp-content/uploads/2022/07/TandH_011.png 877w, https://d9m.one/wp-content/uploads/2022/07/TandH_011-300x217.png 300w, https://d9m.one/wp-content/uploads/2022/07/TandH_011-768x554.png 768w" sizes="(max-width: 658px) 100vw, 658px" /></a><figcaption>トゲ制御</figcaption></figure>



<p class="has-medium-font-size"><strong>・コンポーネント削除</strong></p>



<ol class="wp-block-list"><li>ヒエラルキーの「Toge」をクリック</li><li>インスペクターの「Char Ctrl(スクリプト)」にある縦の三点リーダーをクリック</li><li>「コンポーネントを削除」をクリック</li></ol>



<p class="has-medium-font-size"><strong>・スクリプト編集開始</strong></p>



<ol class="wp-block-list"><li>プロジェクトの「Assets&gt;CharCtrl」をダブルクリック</li></ol>



<p class="has-medium-font-size"><strong>・スクリプト関数定義</strong></p>



<ol class="wp-block-list"><li>FixedUpdate関数の後に以下の関数を追加</li></ol>



<div class="hcb_wrap"><pre class="prism line-numbers lang-csharp" data-file="CharCtrl.cs" data-lang="C#"><code>    // 指定位置にあるオブジェクトを取得
    GameObject GetObject(Vector3 pos)
    {
        // 指定位置にオブジェクトが無いのでNULLを返す
        return null;
    }
</code></pre></div>



<p class="has-medium-font-size"><strong>・スクリプト関数作成</strong></p>



<ol class="wp-block-list"><li>GetObject内の「指定位置にオブジェクトが無いのでNULLを返す」前に以下の処理を追加</li></ol>



<div class="hcb_wrap"><pre class="prism line-numbers lang-csharp" data-file="CharCtrl.cs" data-lang="C#"><code>        // 小数点誤差を補正
        float posX = Mathf.Floor(pos.x + 0.5f);
        float posZ = Mathf.Floor(pos.z + 0.5f);
        // 処理対象とするタグの一覧を作成
        string[] tags = new string[] { &quot;Toge&quot; };
        // タグを１つ１つ処理
        for (int i = 0; i &lt; tags.Length; i++)
        {
            // 指定タグのオブジェクト一覧を取得
            GameObject[] objs = GameObject.FindGameObjectsWithTag(tags[i]);
            // オブジェクトを１つ１つ処理
            for (int j = 0; j &lt; objs.Length; j++)
            {
                // 指定位置に存在するオブジェクトを返す
                Vector3 objPos = objs[j].transform.position;
                if (objPos.x == posX && objPos.z == posZ) return objs[j];
            }
        }
</code></pre></div>



<p class="has-medium-font-size"><strong>・スクリプト関数呼び出し</strong></p>



<ol class="wp-block-list"><li>FixedUpdate関数の最後に以下の処理を記述</li></ol>



<div class="hcb_wrap"><pre class="prism line-numbers lang-csharp" data-file="CharCtrl.cs" data-lang="C#"><code>        // 重なったオブジェクトを取得
        GameObject obj = GetObject(transform.position);
        // トゲと重なったら自分とトゲを削除
        if (obj != null && obj.tag == &quot;Toge&quot;)
        {
            Destroy(gameObject);
            Destroy(obj);
        }
</code></pre></div>



<p class="has-medium-font-size"><strong>・スクリプト保存</strong></p>



<ol class="wp-block-list"><li>CTRLを押しながらSキーを押す</li></ol>



<p class="has-medium-font-size"><strong>・Unityに戻ってスクリプトをビルド</strong></p>



<ol class="wp-block-list"><li>Unityエディタのタイトルをクリック</li></ol>



<p class="has-medium-font-size"><strong>・プロジェクト保存</strong></p>



<ol class="wp-block-list"><li>CTRLを押しながらSキーを押す</li></ol>
</div>



<h4 class="wp-block-heading"><span id="toc19">▷動作確認</span></h4>



<div class="wp-block-group is-layout-flow wp-block-group-is-layout-flow">
<p>ヒシガタがトゲと衝突したら両方消えるかどうか、プレビューして確認します。</p>



<figure class="wp-block-image size-full is-resized"><a href="https://d9m.one/wp-content/uploads/2022/07/TandH_012.png"><img decoding="async" src="https://d9m.one/wp-content/uploads/2022/07/TandH_012.png" alt="" class="wp-image-821" width="658" height="475" srcset="https://d9m.one/wp-content/uploads/2022/07/TandH_012.png 877w, https://d9m.one/wp-content/uploads/2022/07/TandH_012-300x217.png 300w, https://d9m.one/wp-content/uploads/2022/07/TandH_012-768x554.png 768w" sizes="(max-width: 658px) 100vw, 658px" /></a><figcaption>動作確認</figcaption></figure>



<p class="has-medium-font-size"><strong>・プレビュー開始</strong></p>



<ol class="wp-block-list"><li>エディタ上中央の「▶」をクリック</li></ol>



<p class="has-medium-font-size"><strong>・動作確認</strong></p>



<ol class="wp-block-list"><li>ヒシガタとトゲがぶつかったら両方消えることを確認</li></ol>



<p class="has-medium-font-size"><strong>・プレビュー終了</strong></p>



<ol class="wp-block-list"><li>エディタ上中央の「▶」をクリック</li></ol>



<p class="has-medium-font-size"><strong>・プレビュー開始</strong></p>



<ol class="wp-block-list"><li>エディタ上中央の「▶」をクリック</li></ol>



<p class="has-medium-font-size"><strong>・プレビュー一時停止</strong></p>



<ol class="wp-block-list"><li>エディタ上中央の「||」をクリック</li></ol>



<p class="has-medium-font-size"><strong>・仮編集</strong></p>



<ol class="wp-block-list"><li>ヒエラルキーの「Toge」をクリック</li><li>インスペクターのTransformにある位置を(0, 0, 2)に設定</li></ol>



<p class="has-medium-font-size"><strong>・プレビュー再開</strong></p>



<ol class="wp-block-list"><li>エディタ上中央の「||」をクリック</li></ol>



<p class="has-medium-font-size"><strong>・動作確認</strong></p>



<ol class="wp-block-list"><li>タマとトゲがぶつかったら両方消えることを確認</li></ol>



<p class="has-medium-font-size"><strong>・プレビュー終了</strong></p>



<ol class="wp-block-list"><li>エディタ上中央の「▶」をクリック</li></ol>
</div>



<h4 class="wp-block-heading"><span id="toc20">▷スクリプト記述例</span></h4>



<div class="wp-block-group is-layout-flow wp-block-group-is-layout-flow">
<p>「トゲと重なったら自分とトゲを削除する」スクリプトの記述例です。</p>



<div class="hcb_wrap"><pre class="prism line-numbers lang-csharp" data-file="CharCtrl.cs" data-lang="C#"><code>using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class CharCtrl : MonoBehaviour
{
    float moveFrame = 30;       // １歩に何フレームかけるか
    float frameCount = 0;       // 経過フレーム数

    // Start is called before the first frame update
    void Start()
    {
        
    }

    // Update is called once per frame
    void Update()
    {
        
    }

    // 物理フレーム更新時に処理
    void FixedUpdate()
    {
        // タグ検索でタマとヒシガタの一覧を取得する
        GameObject[] tamas = GameObject.FindGameObjectsWithTag(&quot;Player&quot;);
        GameObject[] hisis = GameObject.FindGameObjectsWithTag(&quot;Enemy&quot;);

        // １歩分のフレームが経過するまで何もしない
        frameCount++;
        if (frameCount &lt; moveFrame) return;

        // 経過フレーム数を0初期化する
        frameCount = 0;

        // 向いている方向に１メートル進む
        transform.position += transform.forward;

        // ヒシガタとタマが衝突したら両方削除
        if (tamas.Length != 0 && hisis.Length != 0)
        {
            // タマとヒシガタの位置が同じだった場合
            if (tamas[0].transform.position == hisis[0].transform.position)
            {
                // タマとヒシガタを削除
                Destroy(tamas[0]);
                Destroy(hisis[0]);
            }
        }

        // 重なったオブジェクトを取得
        GameObject obj = GetObject(transform.position);
        // トゲと重なったら自分とトゲを削除
        if (obj != null && obj.tag == &quot;Toge&quot;)
        {
            Destroy(gameObject);
            Destroy(obj);
        }
    }

    // 指定位置にあるオブジェクトを取得
    GameObject GetObject(Vector3 pos)
    {
        // 小数点誤差を補正
        float posX = Mathf.Floor(pos.x + 0.5f);
        float posZ = Mathf.Floor(pos.z + 0.5f);
        // 処理対象とするタグの一覧を作成
        string[] tags = new string[] { &quot;Toge&quot; };
        // タグを１つ１つ処理
        for (int i = 0; i &lt; tags.Length; i++)
        {
            // 指定タグのオブジェクト一覧を取得
            GameObject[] objs = GameObject.FindGameObjectsWithTag(tags[i]);
            // オブジェクトを１つ１つ処理
            for (int j = 0; j &lt; objs.Length; j++)
            {
                // 指定位置に存在するオブジェクトを返す
                Vector3 objPos = objs[j].transform.position;
                if (objPos.x == posX && objPos.z == posZ) return objs[j];
            }
        }

        // 指定位置にオブジェクトが無いのでNULLを返す
        return null;
    }
}
</code></pre></div>
</div>



<div style="height:16px" aria-hidden="true" class="wp-block-spacer"></div>
</div>



<h2 class="has-background has-large-font-size wp-block-heading" style="background-color:#f1e0f8;font-style:normal;font-weight:700"><span id="toc21">■オブジェクト作成</span></h2>



<div style="height:16px" aria-hidden="true" class="wp-block-spacer"></div>



<h3 class="has-background has-medium-font-size wp-block-heading" style="background-color:#e5f7fd"><span id="toc22">●床作成</span></h3>



<div class="wp-block-group is-layout-flow wp-block-group-is-layout-flow">
<div style="height:16px" aria-hidden="true" class="wp-block-spacer"></div>



<p>タマやヒシガタが動き回る「地面」を作成します。</p>



<h4 class="wp-block-heading"><span id="toc23">▷床作成</span></h4>



<div class="wp-block-group is-layout-flow wp-block-group-is-layout-flow">
<p>平面を作成してTransformの位置を(4.5, -0.5, 4.5)とし、グレーのチェッカー模様に設定したマテリアルを割り当てます。</p>



<figure class="wp-block-image size-full is-resized"><a href="https://d9m.one/wp-content/uploads/2022/07/TandH_013.png"><img decoding="async" src="https://d9m.one/wp-content/uploads/2022/07/TandH_013.png" alt="" class="wp-image-823" width="658" height="475" srcset="https://d9m.one/wp-content/uploads/2022/07/TandH_013.png 877w, https://d9m.one/wp-content/uploads/2022/07/TandH_013-300x217.png 300w, https://d9m.one/wp-content/uploads/2022/07/TandH_013-768x554.png 768w" sizes="(max-width: 658px) 100vw, 658px" /></a><figcaption>床作成</figcaption></figure>



<p class="has-medium-font-size"><strong>・平面作成</strong></p>



<ol class="wp-block-list"><li>ヒエラルキー左上の「＋」をクリック</li><li>「3Dオブジェクト＞平面」をクリック</li><li>「Floor」と入力し、ENTERキーを押す</li></ol>



<p class="has-medium-font-size"><strong>・位置設定</strong></p>



<ol class="wp-block-list"><li>インスペクターのTransformにある位置を(4.5, -0.5, 4.5)とする</li></ol>



<p class="has-medium-font-size"><strong>・マテリアル作成</strong></p>



<ol class="wp-block-list"><li>プロジェクトの「Assets」を右クリックし、「作成＞マテリアル」をクリック</li><li>「matFloor」と入力し、ENTERキーを押す</li></ol>



<p class="has-medium-font-size"><strong>・マテリアルテクスチャ設定</strong></p>



<ol class="wp-block-list"><li>インスペクターの「Main Maps&gt;アルベド」左の◎をクリックし、「Default-Checker-Gray」をダブルクリック</li></ol>



<p class="has-medium-font-size"><strong>・マテリアル色設定</strong></p>



<ol class="wp-block-list"><li>インスペクターの「Main Maps&gt;アルベド＞カラーバー」をクリックし、色ダイアログの16進数を「CCCCCC」に設定</li><li>色ダイアログの右上にある「×」をクリック</li></ol>



<p class="has-medium-font-size"><strong>・マテリアルタイリング設定</strong></p>



<ol class="wp-block-list"><li>インスペクターの「Main Maps&gt;タイリング」を(5, 5)に設定</li></ol>



<p class="has-medium-font-size"><strong>・マテリアル割り当て</strong></p>



<ol class="wp-block-list"><li>プロジェクトの「matFloor」をヒエラルキーの「Floor」にドラッグ＆ドロップ</li></ol>



<p class="has-medium-font-size"><strong><strong><strong>・プロジェクト保存</strong></strong></strong></p>



<ol class="wp-block-list"><li>CTRLを押しながらSキーを押す</li></ol>
</div>



<div style="height:16px" aria-hidden="true" class="wp-block-spacer"></div>
</div>



<h3 class="has-background has-medium-font-size wp-block-heading" style="background-color:#e5f7fd"><span id="toc24">●壁作成</span></h3>



<div class="wp-block-group is-layout-flow wp-block-group-is-layout-flow">
<div style="height:16px" aria-hidden="true" class="wp-block-spacer"></div>



<p>タマとヒシガタの移動を停止させる壁を作成します。<br>移動先に壁がある場合、推進力を失って停止します。</p>



<h4 class="wp-block-heading"><span id="toc25">▷壁作成</span></h4>



<div class="wp-block-group is-layout-flow wp-block-group-is-layout-flow">
<p>箱を作成してTransformの位置を(0, 0, 5)とし、オレンジ色の「Background」に設定したマテリアルを割り当てます。</p>



<figure class="wp-block-image size-full is-resized"><a href="https://d9m.one/wp-content/uploads/2022/07/TandH_014.png"><img decoding="async" src="https://d9m.one/wp-content/uploads/2022/07/TandH_014.png" alt="" class="wp-image-825" width="658" height="475" srcset="https://d9m.one/wp-content/uploads/2022/07/TandH_014.png 877w, https://d9m.one/wp-content/uploads/2022/07/TandH_014-300x217.png 300w, https://d9m.one/wp-content/uploads/2022/07/TandH_014-768x554.png 768w" sizes="(max-width: 658px) 100vw, 658px" /></a><figcaption>壁作成</figcaption></figure>



<p class="has-medium-font-size"><strong>・箱作成</strong></p>



<ol class="wp-block-list"><li>ヒエラルキー左上の「＋」をクリック</li><li>「3Dオブジェクト＞キューブ」をクリック</li><li>「Block」と入力し、ENTERキーを押す</li></ol>



<p class="has-medium-font-size">・<strong>位置、回転、スケール設定</strong></p>



<ol class="wp-block-list"><li>インスペクターのTransformにある位置を(0, 0, 5)とする</li><li>インスペクターのTransformにある回転を(0, 0, 0)とする</li><li>インスペクターのTransformにあるスケールを(1, 1, 1)とする</li></ol>



<p class="has-medium-font-size"><strong>・マテリアル作成</strong></p>



<ol class="wp-block-list"><li>プロジェクトの「Assets」を右クリックし、「作成＞マテリアル」をクリック</li><li>「matBlock」と入力し、ENTERキーを押す</li></ol>



<p class="has-medium-font-size"><strong>・マテリアルテクスチャ設定</strong></p>



<ol class="wp-block-list"><li>インスペクターの「Main Maps&gt;アルベド」左の◎をクリックし、「Background」をダブルクリック</li></ol>



<p class="has-medium-font-size"><strong>・マテリアル色設定</strong></p>



<ol class="wp-block-list"><li>インスペクターの「Main Maps&gt;アルベド＞カラーバー」をクリックし、色ダイアログの16進数を「FF8000」に設定</li><li>色ダイアログの右上にある「×」をクリック</li></ol>



<p class="has-medium-font-size"><strong>・マテリアル割り当て</strong></p>



<ol class="wp-block-list"><li>プロジェクトの「matBlock」をヒエラルキーの「Block」にドラッグ＆ドロップ</li></ol>
</div>



<h4 class="wp-block-heading"><span id="toc26">▷壁認識</span></h4>



<div class="wp-block-group is-layout-flow wp-block-group-is-layout-flow">
<p>タグ「Block」を作成し、壁に割り当てます。</p>



<figure class="wp-block-image size-full is-resized"><a href="https://d9m.one/wp-content/uploads/2022/07/TandH_015.png"><img decoding="async" src="https://d9m.one/wp-content/uploads/2022/07/TandH_015.png" alt="" class="wp-image-827" width="658" height="475" srcset="https://d9m.one/wp-content/uploads/2022/07/TandH_015.png 877w, https://d9m.one/wp-content/uploads/2022/07/TandH_015-300x217.png 300w, https://d9m.one/wp-content/uploads/2022/07/TandH_015-768x554.png 768w" sizes="(max-width: 658px) 100vw, 658px" /></a><figcaption>壁認識</figcaption></figure>



<p class="has-medium-font-size"><strong>・タグ作成</strong></p>



<ol class="wp-block-list"><li>ヒエラルキーの「Block」をクリック</li><li>インスペクター上部のタグドロップダウンをクリックし、「タグを追加&#8230;」をクリック</li><li>インスペクター「Tag &amp; Layers」にあるタグ欄右下の「＋」をクリック</li><li>「Block」と入力してENTERを押す</li></ol>



<p class="has-medium-font-size"><strong>・タグ割り当て</strong></p>



<ol class="wp-block-list"><li>ヒエラルキーの「Block」をクリック</li><li>インスペクターのタグドロップダウンをクリックし、「Block」をクリック</li></ol>
</div>



<h4 class="wp-block-heading"><span id="toc27">▷壁衝突</span></h4>



<div class="wp-block-group is-layout-flow wp-block-group-is-layout-flow">
<p>移動先に壁かジャンプ台があったら移動停止するようにCharCtrlを修正します。</p>



<figure class="wp-block-image size-full is-resized"><a href="https://d9m.one/wp-content/uploads/2022/07/TandH_016.png"><img decoding="async" src="https://d9m.one/wp-content/uploads/2022/07/TandH_016.png" alt="" class="wp-image-828" width="658" height="475" srcset="https://d9m.one/wp-content/uploads/2022/07/TandH_016.png 877w, https://d9m.one/wp-content/uploads/2022/07/TandH_016-300x217.png 300w, https://d9m.one/wp-content/uploads/2022/07/TandH_016-768x554.png 768w" sizes="(max-width: 658px) 100vw, 658px" /></a><figcaption>壁衝突</figcaption></figure>



<p class="has-medium-font-size">・<strong>スクリプト編集開始</strong></p>



<ol class="wp-block-list"><li>プロジェクトの「Assets&gt;CharCtrl」をダブルクリック</li></ol>



<p class="has-medium-font-size"><strong>・スクリプト関数修正</strong></p>



<ol class="wp-block-list"><li>FixedUpdate関数内の「経過フレーム数を0初期化する」の後に以下のスクリプトを追加</li></ol>



<div class="hcb_wrap"><pre class="prism line-numbers lang-csharp" data-file="CharCtrl.cs" data-lang="C#"><code>        // 移動先に壁かジャンプ台があったら移動終了
        GameObject moveObj = GetObject(transform.position + transform.forward);
        if (moveObj != null && (moveObj.tag == &quot;Block&quot; || moveObj.tag == &quot;Jump&quot;))
        {
            return;
        }
</code></pre></div>



<p class="has-medium-font-size"><strong>・スクリプト関数修正</strong></p>



<ol class="wp-block-list"><li>GetObject関数内の「処理対象とするタグの一覧を作成」を以下のスクリプトのように修正</li></ol>



<div class="hcb_wrap"><pre class="prism line-numbers lang-csharp" data-file="CharCtrl.cs" data-lang="C#"><code>        // 処理対象とするタグの一覧を作成
        string[] tags = new string[] { &quot;Toge&quot;, &quot;Block&quot; };
</code></pre></div>



<p class="has-medium-font-size"><strong>・スクリプト保存</strong></p>



<ol class="wp-block-list"><li>CTRLを押しながらSキーを押す</li></ol>



<p class="has-medium-font-size"><strong>・Unityに戻ってスクリプトをビルド</strong></p>



<ol class="wp-block-list"><li>Unityエディタのタイトルをクリック</li></ol>



<p class="has-medium-font-size"><strong>・プロジェクト保存</strong></p>



<ol class="wp-block-list"><li>CTRLを押しながらSキーを押す</li></ol>
</div>



<h4 class="wp-block-heading"><span id="toc28">▷動作確認</span></h4>



<div class="wp-block-group is-layout-flow wp-block-group-is-layout-flow">
<p>タマが壁に衝突したら止まるかどうか、プレビューして確認します。</p>



<figure class="wp-block-image size-full is-resized"><a href="https://d9m.one/wp-content/uploads/2022/07/TandH_017.png"><img decoding="async" src="https://d9m.one/wp-content/uploads/2022/07/TandH_017.png" alt="" class="wp-image-829" width="658" height="475" srcset="https://d9m.one/wp-content/uploads/2022/07/TandH_017.png 877w, https://d9m.one/wp-content/uploads/2022/07/TandH_017-300x217.png 300w, https://d9m.one/wp-content/uploads/2022/07/TandH_017-768x554.png 768w" sizes="(max-width: 658px) 100vw, 658px" /></a><figcaption>動作確認</figcaption></figure>



<p class="has-medium-font-size"><strong>・プレビュー開始</strong></p>



<ol class="wp-block-list"><li>エディタ上中央の「▶」をクリック</li></ol>



<p class="has-medium-font-size"><strong>・動作確認</strong></p>



<ol class="wp-block-list"><li>タマが壁に衝突したら止まることを確認</li></ol>



<p class="has-medium-font-size"><strong><strong>・プレビュー終了</strong></strong></p>



<ol class="has-medium-font-size wp-block-list"><li>エディタ上中央の「▶」をクリック</li></ol>
</div>



<div style="height:16px" aria-hidden="true" class="wp-block-spacer"></div>
</div>



<h3 class="has-background has-medium-font-size wp-block-heading" style="background-color:#e5f7fd"><span id="toc29">●ジャンプ台作成</span></h3>



<div style="height:16px" aria-hidden="true" class="wp-block-spacer"></div>



<div class="wp-block-group is-layout-flow wp-block-group-is-layout-flow">
<p>画面をクリックするとジャンプ台の隣にあるタマとヒシガタを押すようにして移動を開始させます。<br>また、壁と同じように移動先にジャンプ台があると移動を停止します。</p>



<h4 class="wp-block-heading"><span id="toc30">▷ジャンプ台作成</span></h4>



<div class="wp-block-group is-layout-flow wp-block-group-is-layout-flow">
<p>箱を作成してTransformの位置を(0, 0, -1)とし、緑色の「Knob」に設定したマテリアルを割り当てます。</p>



<figure class="wp-block-image size-full is-resized"><a href="https://d9m.one/wp-content/uploads/2022/07/TandH_018.png"><img decoding="async" src="https://d9m.one/wp-content/uploads/2022/07/TandH_018.png" alt="" class="wp-image-831" width="658" height="475" srcset="https://d9m.one/wp-content/uploads/2022/07/TandH_018.png 877w, https://d9m.one/wp-content/uploads/2022/07/TandH_018-300x217.png 300w, https://d9m.one/wp-content/uploads/2022/07/TandH_018-768x554.png 768w" sizes="(max-width: 658px) 100vw, 658px" /></a><figcaption>ジャンプ台作成</figcaption></figure>



<p class="has-medium-font-size"><strong>・箱作成</strong></p>



<ol class="wp-block-list"><li>ヒエラルキー左上の「＋」をクリック</li><li>「3Dオブジェクト＞キューブ」をクリック</li><li>「Jump」と入力し、ENTERキーを押す</li></ol>



<p class="has-medium-font-size"><strong>・<strong>位置、回転、スケール設定</strong></strong></p>



<ol class="wp-block-list"><li>インスペクターのTransformにある位置を(0, 0, -1)とする</li><li>インスペクターのTransformにある回転を(0, 0, 0)とする</li><li>インスペクターのTransformにあるスケールを(1, 1, 1)とする</li></ol>



<p class="has-medium-font-size"><strong><strong>・マテリアル作成</strong></strong></p>



<ol class="wp-block-list"><li>プロジェクトの「Assets」を右クリックし、「作成＞マテリアル」をクリック</li><li>「matJump」と入力し、ENTERキーを押す</li></ol>



<p class="has-medium-font-size"><strong><strong>・マテリアルテクスチャ設定</strong></strong></p>



<ol class="wp-block-list"><li>インスペクターの「Main Maps&gt;アルベド」左の◎をクリックし、「Knob」をダブルクリック</li></ol>



<p class="has-medium-font-size"><strong><strong>・マテリアル色設定</strong></strong></p>



<ol class="wp-block-list"><li>インスペクターの「Main Maps&gt;アルベド＞カラーバー」をクリックし、色ダイアログの16進数を「008000」に設定</li><li>色ダイアログの右上にある「×」をクリック</li></ol>



<p class="has-medium-font-size"><strong><strong>・マテリアル割り当て</strong></strong></p>



<ol class="wp-block-list"><li>プロジェクトの「matJump」をヒエラルキーの「Jump」にドラッグ＆ドロップ</li></ol>
</div>



<h4 class="wp-block-heading"><span id="toc31">▷ジャンプ台認識</span></h4>



<div class="wp-block-group is-layout-flow wp-block-group-is-layout-flow">
<p>タグ「Jump」を作成し、ジャンプ台に割り当てます。</p>



<figure class="wp-block-image size-full is-resized"><a href="https://d9m.one/wp-content/uploads/2022/07/TandH_019.png"><img decoding="async" src="https://d9m.one/wp-content/uploads/2022/07/TandH_019.png" alt="" class="wp-image-833" width="658" height="475" srcset="https://d9m.one/wp-content/uploads/2022/07/TandH_019.png 877w, https://d9m.one/wp-content/uploads/2022/07/TandH_019-300x217.png 300w, https://d9m.one/wp-content/uploads/2022/07/TandH_019-768x554.png 768w" sizes="(max-width: 658px) 100vw, 658px" /></a><figcaption>ジャンプ台認識</figcaption></figure>



<p class="has-medium-font-size"><strong>・タグ作成</strong></p>



<ol class="wp-block-list"><li>ヒエラルキーの「Jump」をクリック</li><li>インスペクターのタグドロップダウンをクリックし、「タグを追加&#8230;」をクリック</li><li>インスペクター「Tag &amp; Layers」にあるタグ欄右下の「＋」をクリック</li><li>「Jump」と入力してENTERを押す</li></ol>



<p class="has-medium-font-size"><strong>・タグ割り当て</strong></p>



<ol class="wp-block-list"><li>ヒエラルキーの「Jump」をクリック</li><li>インスペクターのタグドロップダウンをクリックし、「Jump」をクリック</li></ol>
</div>



<h4 class="wp-block-heading"><span id="toc32">▷ジャンプ台制御</span></h4>



<div class="wp-block-group is-layout-flow wp-block-group-is-layout-flow">
<p>ゲーム画面をクリックした時にタマかヒシガタが隣にあったら移動を開始するようCharCtrlを修正します。</p>



<figure class="wp-block-image size-full is-resized"><a href="https://d9m.one/wp-content/uploads/2022/07/TandH_020.png"><img decoding="async" src="https://d9m.one/wp-content/uploads/2022/07/TandH_020.png" alt="" class="wp-image-835" width="658" height="475" srcset="https://d9m.one/wp-content/uploads/2022/07/TandH_020.png 877w, https://d9m.one/wp-content/uploads/2022/07/TandH_020-300x217.png 300w, https://d9m.one/wp-content/uploads/2022/07/TandH_020-768x554.png 768w" sizes="(max-width: 658px) 100vw, 658px" /></a><figcaption>ジャンプ台制御</figcaption></figure>



<p class="has-medium-font-size"><strong>・スクリプト編集開始</strong></p>



<ol class="wp-block-list"><li>プロジェクトの「Assets&gt;CharCtrl」をダブルクリック</li></ol>



<p class="has-medium-font-size"><strong>・スクリプト変数追加</strong></p>



<ol class="wp-block-list"><li>「１歩に何フレームかけるか」の変数の前に以下の変数を追加</li></ol>



<div class="hcb_wrap"><pre class="prism line-numbers lang-plain"><code>    bool moveFlag = false;      // 移動中かどうか
</code></pre></div>



<p class="has-medium-font-size"><strong>・スクリプト関数修正</strong></p>



<ol class="wp-block-list"><li>Update関数内に以下のスクリプトを記述</li></ol>



<div class="hcb_wrap"><pre class="prism line-numbers lang-csharp" data-file="CharCtrl.cs" data-lang="C#"><code>        // マウスクリックされた場合
        if (Input.GetMouseButtonUp(0) == true)
        {
        }
</code></pre></div>



<p class="has-medium-font-size"><strong>・スクリプト関数修正</strong></p>



<ol class="wp-block-list"><li>Update関数内の「マウスクリックされた場合」の条件内に以下のスクリプトを記述</li></ol>



<div class="hcb_wrap"><pre class="prism line-numbers lang-csharp" data-file="CharCtrl.cs" data-lang="C#"><code>            // 現在の回転値を保存
            Quaternion rot = transform.rotation;
            // 上下左右のオブジェクトを取得
            transform.rotation = Quaternion.Euler(0, 0, 0);
            GameObject objU = GetObject(transform.position + transform.forward);
            GameObject objD = GetObject(transform.position - transform.forward);
            GameObject objL = GetObject(transform.position - transform.right);
            GameObject objR = GetObject(transform.position + transform.right);
</code></pre></div>



<p class="has-medium-font-size"><strong>・スクリプト関数修正</strong></p>



<ol class="wp-block-list"><li>Update関数内の「上下左右のオブジェクトを取得」処理の後に以下のスクリプトを記述</li></ol>



<div class="hcb_wrap"><pre class="prism line-numbers lang-csharp" data-file="CharCtrl.cs" data-lang="C#"><code>            // 指定方向がジャンプ台かつ逆側がなにも無いかトゲの場合、オブジェクトをジャンプ台の逆側に向ける
            float dir = -1;
            if (objU != null && objU.tag == &quot;Jump&quot; && (objD == null || objD.tag == &quot;Toge&quot;)) dir = 180;
            if (objD != null && objD.tag == &quot;Jump&quot; && (objU == null || objU.tag == &quot;Toge&quot;)) dir = 0;
            if (objL != null && objL.tag == &quot;Jump&quot; && (objR == null || objR.tag == &quot;Toge&quot;)) dir = 90;
            if (objR != null && objR.tag == &quot;Jump&quot; && (objL == null || objL.tag == &quot;Toge&quot;)) dir = 270;
            if (dir != -1)
            {
                moveFlag = true;
                rot = Quaternion.Euler(0, dir, 0);
            }
            // 回転値を設定
            transform.rotation = rot;
</code></pre></div>



<p class="has-medium-font-size"><strong>・スクリプト関数修正</strong></p>



<ol class="wp-block-list"><li>FixedUpdate関数内の「経過フレーム数を0初期化する」処理の後に以下のスクリプトを記述</li></ol>



<div class="hcb_wrap"><pre class="prism line-numbers lang-csharp" data-file="CharCtrl.cs" data-lang="C#"><code>        // 移動していない場合は終了
        if (moveFlag == false) return;
</code></pre></div>



<p class="has-medium-font-size"><strong>・スクリプト関数修正</strong></p>



<ol class="wp-block-list"><li>FixedUpdate関数内の「移動先に壁かジャンプ台があったら移動終了」条件内のreturn前に以下のスクリプトを記述</li></ol>



<div class="hcb_wrap"><pre class="prism line-numbers lang-csharp" data-file="CharCtrl.cs" data-lang="C#"><code>            moveFlag = false;
</code></pre></div>



<p class="has-medium-font-size"><strong>・スクリプト関数修正</strong></p>



<ol class="wp-block-list"><li>GetObject関数内の「処理対象とするタグの一覧を作成」を以下のスクリプトのように修正</li></ol>



<div class="hcb_wrap"><pre class="prism line-numbers lang-csharp" data-file="CharCtrl.cs" data-lang="C#"><code>        // 処理対象とするタグの一覧を作成
        string[] tags = new string[] { &quot;Toge&quot;, &quot;Block&quot;, &quot;Jump&quot; };
</code></pre></div>



<p class="has-medium-font-size"><strong>・スクリプト保存</strong></p>



<ol class="wp-block-list"><li>CTRLを押しながらSキーを押す</li></ol>



<p class="has-medium-font-size"><strong><strong>・Unityに戻ってスクリプトをビルド</strong></strong></p>



<ol class="wp-block-list"><li>Unityエディタのタイトルをクリック</li></ol>



<p class="has-medium-font-size"><strong>・プロジェクト保存</strong></p>



<ol class="wp-block-list"><li>CTRLを押しながらSキーを押す</li></ol>
</div>



<h4 class="wp-block-heading"><span id="toc33">▷動作確認</span></h4>



<div class="wp-block-group is-layout-flow wp-block-group-is-layout-flow">
<p>クリックしたらタマが動き出すかどうか、プレビューして確認します。</p>



<figure class="wp-block-image size-full is-resized"><a href="https://d9m.one/wp-content/uploads/2022/07/TandH_021.png"><img decoding="async" src="https://d9m.one/wp-content/uploads/2022/07/TandH_021.png" alt="" class="wp-image-837" width="658" height="475" srcset="https://d9m.one/wp-content/uploads/2022/07/TandH_021.png 877w, https://d9m.one/wp-content/uploads/2022/07/TandH_021-300x217.png 300w, https://d9m.one/wp-content/uploads/2022/07/TandH_021-768x554.png 768w" sizes="(max-width: 658px) 100vw, 658px" /></a><figcaption>動作確認</figcaption></figure>



<p class="has-medium-font-size"><strong>・プレビュー開始</strong></p>



<ol class="wp-block-list"><li>エディタ上中央の「▶」をクリック</li></ol>



<p class="has-medium-font-size"><strong>・動作確認</strong></p>



<ol class="wp-block-list"><li>タマとヒシガタが動いていないことを確認</li><li>ゲームビューをクリックしたらジャンプ台と隣接しているタマが動き出すことを確認</li></ol>



<p class="has-medium-font-size"><strong>・プレビュー終了</strong></p>



<ol class="wp-block-list"><li>エディタ上中央の「▶」をクリック</li></ol>
</div>



<h4 class="wp-block-heading"><span id="toc34">▷スクリプト記述例</span></h4>



<div class="wp-block-group is-layout-flow wp-block-group-is-layout-flow">
<p>「クリックしたらタマが動き出す」スクリプトの記述例です。</p>



<div class="hcb_wrap"><pre class="prism line-numbers lang-csharp" data-file="CharCtrl" data-lang="C#"><code>using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class CharCtrl : MonoBehaviour
{
    bool moveFlag = false;      // 移動中かどうか
    float moveFrame = 30;       // １歩に何フレームかけるか
    float frameCount = 0;       // 経過フレーム数

    // Start is called before the first frame update
    void Start()
    {
        
    }

    // Update is called once per frame
    void Update()
    {
        // マウスクリックされた場合
        if (Input.GetMouseButtonUp(0) == true)
        {
            // 現在の回転値を保存
            Quaternion rot = transform.rotation;
            // 上下左右のオブジェクトを取得
            transform.rotation = Quaternion.Euler(0, 0, 0);
            GameObject objU = GetObject(transform.position + transform.forward);
            GameObject objD = GetObject(transform.position - transform.forward);
            GameObject objL = GetObject(transform.position - transform.right);
            GameObject objR = GetObject(transform.position + transform.right);
            // 指定方向がジャンプ台かつ逆側がなにも無いかトゲの場合、オブジェクトをジャンプ台の逆側に向ける
            float dir = -1;
            if (objU != null && objU.tag == &quot;Jump&quot; && (objD == null || objD.tag == &quot;Toge&quot;)) dir = 180;
            if (objD != null && objD.tag == &quot;Jump&quot; && (objU == null || objU.tag == &quot;Toge&quot;)) dir = 0;
            if (objL != null && objL.tag == &quot;Jump&quot; && (objR == null || objR.tag == &quot;Toge&quot;)) dir = 90;
            if (objR != null && objR.tag == &quot;Jump&quot; && (objL == null || objL.tag == &quot;Toge&quot;)) dir = 270;
            if (dir != -1)
            {
                moveFlag = true;
                rot = Quaternion.Euler(0, dir, 0);
            }
            // 回転値を設定
            transform.rotation = rot;
        }
    }

    // 物理フレーム更新時に処理
    void FixedUpdate()
    {
        // タグ検索でタマとヒシガタの一覧を取得する
        GameObject[] tamas = GameObject.FindGameObjectsWithTag(&quot;Player&quot;);
        GameObject[] hisis = GameObject.FindGameObjectsWithTag(&quot;Enemy&quot;);

        // １歩分のフレームが経過するまで何もしない
        frameCount++;
        if (frameCount &lt; moveFrame) return;

        // 経過フレーム数を0初期化する
        frameCount = 0;

        // 移動していない場合は終了
        if (moveFlag == false) return;

        // 移動先に壁かジャンプ台があったら移動終了
        GameObject moveObj = GetObject(transform.position + transform.forward);
        if (moveObj != null && (moveObj.tag == &quot;Block&quot; || moveObj.tag == &quot;Jump&quot;))
        {
            moveFlag = false;
            return;
        }

        // 向いている方向に１メートル進む
        transform.position += transform.forward;

        // ヒシガタとタマが衝突したら両方削除
        if (tamas.Length != 0 && hisis.Length != 0)
        {
            // タマとヒシガタの位置が同じだった場合
            if (tamas[0].transform.position == hisis[0].transform.position)
            {
                // タマとヒシガタを削除
                Destroy(tamas[0]);
                Destroy(hisis[0]);
            }
        }

        // 重なったオブジェクトを取得
        GameObject obj = GetObject(transform.position);
        // トゲと重なったら自分とトゲを削除
        if (obj != null && obj.tag == &quot;Toge&quot;)
        {
            Destroy(gameObject);
            Destroy(obj);
        }
    }

    // 指定位置にあるオブジェクトを取得
    GameObject GetObject(Vector3 pos)
    {
        // 小数点誤差を補正
        float posX = Mathf.Floor(pos.x + 0.5f);
        float posZ = Mathf.Floor(pos.z + 0.5f);
        // 処理対象とするタグの一覧を作成
        string[] tags = new string[] { &quot;Toge&quot;, &quot;Block&quot;, &quot;Jump&quot; };
        // タグを１つ１つ処理
        for (int i = 0; i &lt; tags.Length; i++)
        {
            // 指定タグのオブジェクト一覧を取得
            GameObject[] objs = GameObject.FindGameObjectsWithTag(tags[i]);
            // オブジェクトを１つ１つ処理
            for (int j = 0; j &lt; objs.Length; j++)
            {
                // 指定位置に存在するオブジェクトを返す
                Vector3 objPos = objs[j].transform.position;
                if (objPos.x == posX && objPos.z == posZ) return objs[j];
            }
        }

        // 指定位置にオブジェクトが無いのでNULLを返す
        return null;
    }
}</code></pre></div>
</div>
</div>



<div style="height:16px" aria-hidden="true" class="wp-block-spacer"></div>



<h3 class="has-background has-medium-font-size wp-block-heading" style="background-color:#e5f7fd"><span id="toc35">●ゴール作成</span></h3>



<div style="height:16px" aria-hidden="true" class="wp-block-spacer"></div>



<div class="wp-block-group is-layout-flow wp-block-group-is-layout-flow">
<p>タマと衝突するとクリアになる、「ゴール」を作成します。</p>



<h4 class="wp-block-heading"><span id="toc36">▷ゴール作成</span></h4>



<div class="wp-block-group is-layout-flow wp-block-group-is-layout-flow">
<p>パーティクルシステムを作成して位置を(0, 0, 3)とし、その場に留まって揺らめくエフェクトとします。</p>



<figure class="wp-block-image size-full is-resized"><a href="https://d9m.one/wp-content/uploads/2022/07/TandH_022.png"><img decoding="async" src="https://d9m.one/wp-content/uploads/2022/07/TandH_022.png" alt="" class="wp-image-839" width="658" height="475" srcset="https://d9m.one/wp-content/uploads/2022/07/TandH_022.png 877w, https://d9m.one/wp-content/uploads/2022/07/TandH_022-300x217.png 300w, https://d9m.one/wp-content/uploads/2022/07/TandH_022-768x554.png 768w" sizes="(max-width: 658px) 100vw, 658px" /></a><figcaption>ゴール作成</figcaption></figure>



<p class="has-medium-font-size"><strong>・パーティクルシステム作成</strong></p>



<ol class="wp-block-list"><li>ヒエラルキー左上の「＋」をクリック</li><li>「エフェクト＞パーティクルシステム」をクリック</li><li>「Goal」と入力し、ENTERキーを押す</li></ol>



<p class="has-medium-font-size"><strong><strong>・<strong>位置、回転、スケール設定</strong></strong></strong></p>



<ol class="wp-block-list"><li>インスペクターのTransformにある位置を(0, 0, 3)とする</li><li>インスペクターのTransformにある回転を(-90, 0, 0)とする</li><li>インスペクターのTransformにあるスケールを(1, 1, 1)とする</li></ol>



<p class="has-medium-font-size"><strong>・メインモジュール設定</strong></p>



<p>メインモジュールを以下のように設定します。</p>



<ol class="wp-block-list"><li>インスペクターにあるParticle Systemの「メインモジュール＞継続時間」を(1)に設定</li><li>インスペクターにあるParticle Systemの「メインモジュール＞開始時の生存期間」を(1)に設定</li><li>インスペクターにあるParticle Systemの「メインモジュール＞開始時の速度」を(0)に設定</li><li>インスペクターにあるParticle Systemの「メインモジュール＞開始時の色」右にあるカラーバーをクリックし、色ダイアログの16進数を(FFFF00)に設定</li><li>色ダイアログの右上にある「×」をクリック</li><li>インスペクターにあるParticle Systemの「メインモジュール＞重力モディファイア」を(-0.1）に設定</li></ol>



<p class="has-medium-font-size"><strong>・形状モジュール設定</strong></p>



<p>形状モジュールを以下のように設定します。</p>



<ol class="wp-block-list"><li>形状モジュールの「形状」を(スフィア)に設定</li><li>形状モジュールの「半径」を(0.3)に設定</li><li>形状モジュールの「半径の厚さ」を(0)に設定</li></ol>
</div>



<h4 class="wp-block-heading"><span id="toc37">▷ゴール認識</span></h4>



<div class="wp-block-group is-layout-flow wp-block-group-is-layout-flow">
<p>タグ「Goal」を作成し、ゴールに割り当てます。</p>



<figure class="wp-block-image size-full is-resized"><a href="https://d9m.one/wp-content/uploads/2022/07/TandH_023.png"><img decoding="async" src="https://d9m.one/wp-content/uploads/2022/07/TandH_023.png" alt="" class="wp-image-841" width="658" height="475" srcset="https://d9m.one/wp-content/uploads/2022/07/TandH_023.png 877w, https://d9m.one/wp-content/uploads/2022/07/TandH_023-300x217.png 300w, https://d9m.one/wp-content/uploads/2022/07/TandH_023-768x554.png 768w" sizes="(max-width: 658px) 100vw, 658px" /></a><figcaption>ゴール認識</figcaption></figure>



<p class="has-medium-font-size"><strong>・タグ作成</strong></p>



<ol class="wp-block-list"><li>ヒエラルキーの「Goal」をクリック</li><li>インスペクター上部のタグドロップダウンをクリックし、「タグを追加&#8230;」をクリック</li><li>インスペクター「Tag &amp; Layers」にあるタグ欄右下の「＋」をクリック</li><li>「Goal」と入力してENTERを押す</li></ol>



<p class="has-medium-font-size"><strong>・タグ割り当て</strong></p>



<ol class="wp-block-list"><li>ヒエラルキーの「Goal」をクリック</li><li>インスペクター上部のタグドロップダウンをクリックし、「Goal」をクリック</li></ol>
</div>



<h4 class="wp-block-heading"><span id="toc38">▷ゴール制御</span></h4>



<div class="wp-block-group is-layout-flow wp-block-group-is-layout-flow">
<p>タマとゴールが衝突した時にタマとヒシガタの動きが止まるようにCharCtrlを修正します。</p>



<figure class="wp-block-image size-full is-resized"><a href="https://d9m.one/wp-content/uploads/2022/07/TandH_024.png"><img decoding="async" src="https://d9m.one/wp-content/uploads/2022/07/TandH_024.png" alt="" class="wp-image-843" width="658" height="475" srcset="https://d9m.one/wp-content/uploads/2022/07/TandH_024.png 877w, https://d9m.one/wp-content/uploads/2022/07/TandH_024-300x217.png 300w, https://d9m.one/wp-content/uploads/2022/07/TandH_024-768x554.png 768w" sizes="(max-width: 658px) 100vw, 658px" /></a><figcaption>ゴール制御</figcaption></figure>



<p class="has-medium-font-size"><strong>・スクリプト編集開始</strong></p>



<ol class="wp-block-list"><li>プロジェクトの「Assets&gt;CharCtrl」をダブルクリック</li></ol>



<p class="has-medium-font-size"><strong>・スクリプト変数追加</strong></p>



<ol class="wp-block-list"><li>「移動中かどうか」の変数の前に「プレイ中かどうか」の変数を作成</li></ol>



<div class="hcb_wrap"><pre class="prism line-numbers lang-csharp" data-file="CharCtrl" data-lang="C#"><code>    bool playFlag = true;       // プレイ中かどうか
</code></pre></div>



<p class="has-medium-font-size"><strong>・スクリプト関数修正</strong></p>



<ol class="wp-block-list"><li>FixedUpdate関数の先頭に以下の処理を追加</li></ol>



<div class="hcb_wrap"><pre class="prism line-numbers lang-csharp" data-file="CharCtrl" data-lang="C#"><code>        // プレイ中でない場合は即関数を終了
        if (playFlag == false) return;
</code></pre></div>



<p class="has-medium-font-size"><strong>・スクリプト<strong>関数修正</strong></strong></p>



<ol class="wp-block-list"><li>FixedUpdate関数の最後に以下の処理を追加</li></ol>



<div class="hcb_wrap"><pre class="prism line-numbers lang-csharp" data-file="CharCtrl" data-lang="C#"><code>        // 自分がタマで、かつゴールと重なった場合
        else if (tag == &quot;Player&quot; && obj != null && obj.tag == &quot;Goal&quot;)
        {
            // タマのplayFlagをfalseに設定
            playFlag = false;
        }
</code></pre></div>



<p class="has-medium-font-size"><strong>・スクリプト<strong>関数修正</strong></strong></p>



<ol class="wp-block-list"><li>GetObject関数内の「処理対象とするタグの一覧を作成」を以下のスクリプトのように修正</li></ol>



<div class="hcb_wrap"><pre class="prism line-numbers lang-csharp" data-file="CharCtrl" data-lang="C#"><code>        // 処理対象とするタグの一覧を作成
        string[] tags = new string[] { &quot;Toge&quot;, &quot;Block&quot;, &quot;Jump&quot;, &quot;Goal&quot; };
</code></pre></div>



<p class="has-medium-font-size"><strong><strong>・スクリプト保存</strong></strong></p>



<ol class="wp-block-list"><li>CTRLを押しながらSキーを押す</li></ol>



<p class="has-medium-font-size"><strong><strong><strong><strong>・Unityに戻ってスクリプトをビルド</strong></strong></strong></strong></p>



<ol class="wp-block-list"><li>Unityエディタのタイトルをクリック</li></ol>



<p class="has-medium-font-size"><strong><strong>・プロジェクト保存</strong></strong></p>



<ol class="wp-block-list"><li>CTRLを押しながらSキーを押す</li></ol>
</div>



<h4 class="wp-block-heading"><span id="toc39">▷動作確認</span></h4>



<div class="wp-block-group is-layout-flow wp-block-group-is-layout-flow">
<p>タマとゴールが衝突したらタマの動きが止まるかどうか、プレビューして確認します。</p>



<figure class="wp-block-image size-full is-resized"><a href="https://d9m.one/wp-content/uploads/2022/07/TandH_025.png"><img decoding="async" src="https://d9m.one/wp-content/uploads/2022/07/TandH_025.png" alt="" class="wp-image-844" width="658" height="475" srcset="https://d9m.one/wp-content/uploads/2022/07/TandH_025.png 877w, https://d9m.one/wp-content/uploads/2022/07/TandH_025-300x217.png 300w, https://d9m.one/wp-content/uploads/2022/07/TandH_025-768x554.png 768w" sizes="(max-width: 658px) 100vw, 658px" /></a><figcaption>動作確認</figcaption></figure>



<p class="has-medium-font-size"><strong>・プレビュー開始</strong></p>



<ol class="wp-block-list"><li>エディタ上中央の「▶」をクリック</li></ol>



<p class="has-medium-font-size"><strong><strong>・動作確認</strong></strong></p>



<ol class="wp-block-list"><li>タマとゴールが衝突したらタマの動きが止まることを確認</li></ol>



<p class="has-medium-font-size"><strong>・プレビュー終了</strong></p>



<ol class="wp-block-list"><li>エディタ上中央の「▶」をクリック</li></ol>
</div>



<h4 class="wp-block-heading"><span id="toc40">▷スクリプト記述例</span></h4>



<div class="wp-block-group is-layout-flow wp-block-group-is-layout-flow">
<p>「タマとゴールが衝突したらタマの動きが止まる」スクリプトの記述例です。</p>



<div class="hcb_wrap"><pre class="prism line-numbers lang-csharp" data-file="CharCtrl" data-lang="C#"><code>using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class CharCtrl : MonoBehaviour
{
    bool playFlag = true;       // プレイ中かどうか
    bool moveFlag = false;      // 移動中かどうか
    float moveFrame = 30;       // １歩に何フレームかけるか
    float frameCount = 0;       // 経過フレーム数

    // Start is called before the first frame update
    void Start()
    {
        
    }

    // Update is called once per frame
    void Update()
    {
        // マウスクリックされた場合
        if (Input.GetMouseButtonUp(0) == true)
        {
            // 現在の回転値を保存
            Quaternion rot = transform.rotation;
            // 上下左右のオブジェクトを取得
            transform.rotation = Quaternion.Euler(0, 0, 0);
            GameObject objU = GetObject(transform.position + transform.forward);
            GameObject objD = GetObject(transform.position - transform.forward);
            GameObject objL = GetObject(transform.position - transform.right);
            GameObject objR = GetObject(transform.position + transform.right);

            // 指定方向がジャンプ台かつ逆側がなにも無いかトゲの場合、オブジェクトをジャンプ台の逆側に向ける
            float dir = -1;
            if (objU != null && objU.tag == &quot;Jump&quot; && (objD == null || objD.tag == &quot;Toge&quot;)) dir = 180;
            if (objD != null && objD.tag == &quot;Jump&quot; && (objU == null || objU.tag == &quot;Toge&quot;)) dir = 0;
            if (objL != null && objL.tag == &quot;Jump&quot; && (objR == null || objR.tag == &quot;Toge&quot;)) dir = 90;
            if (objR != null && objR.tag == &quot;Jump&quot; && (objL == null || objL.tag == &quot;Toge&quot;)) dir = 270;
            if (dir != -1)
            {
                moveFlag = true;
                rot = Quaternion.Euler(0, dir, 0);
            }
            // 回転値を設定
            transform.rotation = rot;
        }
    }

    // 物理フレーム更新時に処理
    void FixedUpdate()
    {
        // プレイ中でない場合は即関数を終了
        if (playFlag == false) return;

        // タグ検索でタマとヒシガタの一覧を取得する
        GameObject[] tamas = GameObject.FindGameObjectsWithTag(&quot;Player&quot;);
        GameObject[] hisis = GameObject.FindGameObjectsWithTag(&quot;Enemy&quot;);

        // １歩分のフレームが経過するまで何もしない
        frameCount++;
        if (frameCount &lt; moveFrame) return;

        // 経過フレーム数を0初期化する
        frameCount = 0;

        // 移動していない場合は終了
        if (moveFlag == false) return;

        // 移動先に壁かジャンプ台があったら移動終了
        GameObject moveObj = GetObject(transform.position + transform.forward);
        if (moveObj != null && (moveObj.tag == &quot;Block&quot; || moveObj.tag == &quot;Jump&quot;))
        {
            moveFlag = false;
            return;
        }

        // 向いている方向に１メートル進む
        transform.position += transform.forward;

        // ヒシガタとタマが衝突したら両方削除
        if (tamas.Length != 0 && hisis.Length != 0)
        {
            // タマとヒシガタの位置が同じだった場合
            if (tamas[0].transform.position == hisis[0].transform.position)
            {
                // タマとヒシガタを削除
                Destroy(tamas[0]);
                Destroy(hisis[0]);
            }
        }

        // 重なったオブジェクトを取得
        GameObject obj = GetObject(transform.position);
        // トゲと重なったら自分とトゲを削除
        if (obj != null && obj.tag == &quot;Toge&quot;)
        {
            Destroy(gameObject);
            Destroy(obj);
        }
        // 自分がタマで、かつゴールと重なった場合
        else if (tag == &quot;Player&quot; && obj != null && obj.tag == &quot;Goal&quot;)
        {
            // タマのplayFlagをfalseに設定
            playFlag = false;
        }
    }

    // 指定位置にあるオブジェクトを取得
    GameObject GetObject(Vector3 pos)
    {
        // 小数点誤差を補正
        float posX = Mathf.Floor(pos.x + 0.5f);
        float posZ = Mathf.Floor(pos.z + 0.5f);
        // 処理対象とするタグの一覧を作成
        string[] tags = new string[] { &quot;Toge&quot;, &quot;Block&quot;, &quot;Jump&quot;, &quot;Goal&quot; };
        // タグを１つ１つ処理
        for (int i = 0; i &lt; tags.Length; i++)
        {
            // 指定タグのオブジェクト一覧を取得
            GameObject[] objs = GameObject.FindGameObjectsWithTag(tags[i]);
            // オブジェクトを１つ１つ処理
            for (int j = 0; j &lt; objs.Length; j++)
            {
                // 指定位置に存在するオブジェクトを返す
                Vector3 objPos = objs[j].transform.position;
                if (objPos.x == posX && objPos.z == posZ) return objs[j];
            }
        }

        // 指定位置にオブジェクトが無いのでNULLを返す
        return null;
    }
}
</code></pre></div>
</div>
</div>



<div style="height:16px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="has-background has-large-font-size wp-block-heading" style="background-color:#f1e0f8;font-style:normal;font-weight:700"><span id="toc41">■ゲーム仕上げ</span></h2>



<div style="height:16px" aria-hidden="true" class="wp-block-spacer"></div>



<h3 class="has-background has-medium-font-size wp-block-heading" style="background-color:#e5f7fd"><span id="toc42">●ステージ作成</span></h3>



<div style="height:16px" aria-hidden="true" class="wp-block-spacer"></div>



<div class="wp-block-group is-layout-flow wp-block-group-is-layout-flow">
<h4 class="wp-block-heading"><span id="toc43">▷カメラ設定</span></h4>



<div class="wp-block-group is-layout-flow wp-block-group-is-layout-flow">
<p>ステージを見渡せるようカメラの姿勢を調整します。</p>



<figure class="wp-block-image size-full is-resized"><a href="https://d9m.one/wp-content/uploads/2022/07/TandH_026.png"><img decoding="async" src="https://d9m.one/wp-content/uploads/2022/07/TandH_026.png" alt="" class="wp-image-846" width="658" height="475"/></a><figcaption>カメラ設定</figcaption></figure>



<p class="has-medium-font-size"><strong>・位置、回転、スケール設定</strong></p>



<ol class="wp-block-list"><li>ヒエラルキーの「Main Camera」をクリック</li><li>インスペクターのTransformにある位置を(4.5, 16, -2)とする</li><li>インスペクターのTransformにある回転を(65, 0, 0)とする</li><li>インスペクターのTransformにあるスケールを(1, 1, 1)とする</li></ol>



<p class="has-medium-font-size"><strong>・アスペクト比設定</strong></p>



<ol class="wp-block-list"><li>ゲームビュー上メニュー左から３番目ドロップダウンをクリック</li><li>「9:16 Aspect」をクリック、無い場合は以降を操作</li><li>左下の「＋」をクリック</li><li>ドロップダウン「タイプ」をクリックし、「アスペクト比」をクリック</li><li>幅＆高さの「X」に(9)、「Y」に(16)を入力</li><li>「OK」をクリック</li></ol>
</div>



<h4 class="wp-block-heading"><span id="toc44">▷プレハブ化</span></h4>



<div class="wp-block-group is-layout-flow wp-block-group-is-layout-flow">
<p>ステージに２つ以上配置するオブジェクトをプレハブ化し、量産化しやすくします。<br>対象はトゲ、壁、ジャンプ台の３つです。</p>



<figure class="wp-block-image size-full is-resized"><a href="https://d9m.one/wp-content/uploads/2022/07/TandH_027.png"><img decoding="async" src="https://d9m.one/wp-content/uploads/2022/07/TandH_027.png" alt="" class="wp-image-848" width="658" height="475" srcset="https://d9m.one/wp-content/uploads/2022/07/TandH_027.png 877w, https://d9m.one/wp-content/uploads/2022/07/TandH_027-300x217.png 300w, https://d9m.one/wp-content/uploads/2022/07/TandH_027-768x554.png 768w" sizes="(max-width: 658px) 100vw, 658px" /></a><figcaption>プレハブ化</figcaption></figure>



<p class="has-medium-font-size"><strong>・プレハブ化</strong></p>



<ol class="wp-block-list"><li>ヒエラルキーの「Toge」をプロジェクトの「Assets」にドラッグ＆ドロップ</li><li>ヒエラルキーの「Block」をプロジェクトの「Assets」にドラッグ＆ドロップ</li><li>ヒエラルキーの「Jump」をプロジェクトの「Assets」にドラッグ＆ドロップ</li></ol>
</div>



<h4 class="wp-block-heading"><span id="toc45">▷単一オブジェクト配置</span></h4>



<div class="wp-block-group is-layout-flow wp-block-group-is-layout-flow">
<p>タマ、ヒシガタ、ゴールの位置を設定します。</p>



<figure class="wp-block-image size-full is-resized"><a href="https://d9m.one/wp-content/uploads/2022/07/TandH_028.png"><img decoding="async" src="https://d9m.one/wp-content/uploads/2022/07/TandH_028.png" alt="" class="wp-image-849" width="658" height="475" srcset="https://d9m.one/wp-content/uploads/2022/07/TandH_028.png 877w, https://d9m.one/wp-content/uploads/2022/07/TandH_028-300x217.png 300w, https://d9m.one/wp-content/uploads/2022/07/TandH_028-768x554.png 768w" sizes="(max-width: 658px) 100vw, 658px" /></a><figcaption>単一オブジェクト配置</figcaption></figure>



<p class="has-medium-font-size"><strong>・位置設定</strong></p>



<ol class="wp-block-list"><li>ヒエラルキーの「Tama」をクリック</li><li>インスペクターのTransformにある位置を(1, 0, 8)とする</li><li>ヒエラルキーの「Hisi」をクリック</li><li>インスペクターのTransformにある位置を(8, 0, 1)とする</li><li>ヒエラルキーの「Goal」をクリック</li><li>インスペクターのTransformにある位置を(7, 0, 4)とする</li></ol>
</div>



<h4 class="wp-block-heading"><span id="toc46">▷トゲ配置</span></h4>



<div class="wp-block-group is-layout-flow wp-block-group-is-layout-flow">
<p>トゲ配置用の空オブジェクトにトゲを格納し、複製しながら配置していきます。</p>



<figure class="wp-block-image size-full is-resized"><a href="https://d9m.one/wp-content/uploads/2022/07/TandH_029.png"><img decoding="async" src="https://d9m.one/wp-content/uploads/2022/07/TandH_029.png" alt="" class="wp-image-851" width="658" height="475" srcset="https://d9m.one/wp-content/uploads/2022/07/TandH_029.png 877w, https://d9m.one/wp-content/uploads/2022/07/TandH_029-300x217.png 300w, https://d9m.one/wp-content/uploads/2022/07/TandH_029-768x554.png 768w" sizes="(max-width: 658px) 100vw, 658px" /></a><figcaption>トゲ配置</figcaption></figure>



<p class="has-medium-font-size"><strong>・空オブジェクト作成</strong></p>



<ol class="wp-block-list"><li>ヒエラルキー左上の「＋」をクリック</li><li>「空のオブジェクトを作成」をクリック</li><li>「Toges」と入力し、ENTERキーを押す</li></ol>



<p class="has-medium-font-size"><strong>・位置スケールリセット</strong></p>



<ol class="wp-block-list"><li>インスペクターのTransformにある縦の三点リーダーをクリック</li><li>リセットをクリック</li></ol>



<p class="has-medium-font-size"><strong>・階層設定</strong></p>



<ol class="wp-block-list"><li>ヒエラルキーの「Toge」をヒエラルキーの「Toges」にドラッグ＆ドロップ</li></ol>



<p class="has-medium-font-size"><strong>・位置設定</strong></p>



<ol class="wp-block-list"><li>インスペクターのTransformにある位置を(1, 0, 0)とする</li></ol>



<p class="has-medium-font-size"><strong>・複製、位置設定</strong></p>



<ol class="wp-block-list"><li>ヒエラルキーの「Toges&gt;Toge」をクリック</li><li>CTRLを押しながらDキーを押す</li><li>インスペクターのTransformにある位置を(9, 0, 1)とする</li><li>ヒエラルキーの「Toges&gt;Toge (1)」をクリック</li><li>CTRLを押しながらDキーを押す</li><li>インスペクターのTransformにある位置を(8, 0, 9)とする</li><li>ヒエラルキーの「Toges&gt;Toge (2)」をクリック</li><li>CTRLを押しながらDキーを押す</li><li>インスペクターのTransformにある位置を(0, 0, 8)とする</li><li>ヒエラルキーの「Toges&gt;Toge (3)」をクリック</li><li>CTRLを押しながらDキーを押す</li><li>インスペクターのTransformにある位置を(5, 0, 4)とする</li><li>ヒエラルキーの「Toges&gt;Toge (4)」をクリック</li><li>CTRLを押しながらDキーを押す</li><li>インスペクターのTransformにある位置を(6, 0, 2)とする</li><li>ヒエラルキーの「Toges&gt;Toge (5)」をクリック</li><li>CTRLを押しながらDキーを押す</li><li>インスペクターのTransformにある位置を(5, 0, 2)とする</li><li>ヒエラルキーの「Toges&gt;Toge (6)」をクリック</li><li>CTRLを押しながらDキーを押す</li><li>インスペクターのTransformにある位置を(4, 0, 2)とする</li></ol>



<p class="has-medium-font-size"><strong>・階層を閉じる</strong></p>



<ol class="wp-block-list"><li>ヒエラルキーの「Toges」左にある「▼」をクリック</li></ol>
</div>



<h4 class="wp-block-heading"><span id="toc47">▷ジャンプ台配置</span></h4>



<div class="wp-block-group is-layout-flow wp-block-group-is-layout-flow">
<p>ジャンプ台配置用の空オブジェクトにジャンプ台を格納し、複製しながら配置していきます。</p>



<figure class="wp-block-image size-full is-resized"><a href="https://d9m.one/wp-content/uploads/2022/07/TandH_030.png"><img decoding="async" src="https://d9m.one/wp-content/uploads/2022/07/TandH_030.png" alt="" class="wp-image-852" width="658" height="475" srcset="https://d9m.one/wp-content/uploads/2022/07/TandH_030.png 877w, https://d9m.one/wp-content/uploads/2022/07/TandH_030-300x217.png 300w, https://d9m.one/wp-content/uploads/2022/07/TandH_030-768x554.png 768w" sizes="(max-width: 658px) 100vw, 658px" /></a><figcaption>ジャンプ台配置</figcaption></figure>



<p class="has-medium-font-size"><strong>・空オブジェクト作成</strong></p>



<ol class="wp-block-list"><li>ヒエラルキー左上の「＋」をクリック</li><li>「空のオブジェクトを作成」をクリック</li><li>「Jumps」と入力し、ENTERキーを押す</li></ol>



<p class="has-medium-font-size"><strong>・位置スケールリセット</strong></p>



<ol class="wp-block-list"><li>インスペクターのTransformにある縦の三点リーダーをクリック</li><li>リセットをクリック</li></ol>



<p class="has-medium-font-size"><strong>・階層設定</strong></p>



<ol class="wp-block-list"><li>ヒエラルキーの「Jump」をヒエラルキーの「Jumps」にドラッグ＆ドロップ</li></ol>



<p class="has-medium-font-size"><strong>・位置設定</strong></p>



<ol class="wp-block-list"><li>インスペクターのTransformにある位置を(1, 0, 9)とする</li></ol>



<p class="has-medium-font-size"><strong>・複製、位置設定</strong></p>



<ol class="wp-block-list"><li>ヒエラルキーの「Jumps&gt;Jump」をクリック</li><li>CTRLを押しながらDキーを押す</li><li>インスペクターのTransformにある位置を(0, 0, 1)とする</li><li>ヒエラルキーの「Jumps&gt;Jump (1)」をクリック</li><li>CTRLを押しながらDキーを押す</li><li>インスペクターのTransformにある位置を(8, 0, 0)とする</li><li>ヒエラルキーの「Jumps&gt;Jump (2)」をクリック</li><li>CTRLを押しながらDキーを押す</li><li>インスペクターのTransformにある位置を(9, 0, 8)とする</li><li>ヒエラルキーの「Jumps&gt;Jump (3)」をクリック</li><li>CTRLを押しながらDキーを押す</li><li>インスペクターのTransformにある位置を(6, 0, 9)とする</li><li>ヒエラルキーの「Jumps&gt;Jump (4)」をクリック</li><li>CTRLを押しながらDキーを押す</li><li>インスペクターのTransformにある位置を(5, 0, 9)とする</li><li>ヒエラルキーの「Jumps&gt;Jump (5)」をクリック</li><li>CTRLを押しながらDキーを押す</li><li>インスペクターのTransformにある位置を(4, 0, 9)とする</li><li>ヒエラルキーの「Jumps&gt;Jump (6)」をクリック</li><li>CTRLを押しながらDキーを押す</li><li>インスペクターのTransformにある位置を(3, 0, 4)とする</li></ol>



<p class="has-medium-font-size"><strong>・階層を閉じる</strong></p>



<ol class="wp-block-list"><li>ヒエラルキーの「Jumps」左にある「▼」をクリック</li></ol>
</div>



<h4 class="wp-block-heading"><span id="toc48">▷壁配置</span></h4>



<div class="wp-block-group is-layout-flow wp-block-group-is-layout-flow">
<p>壁配置用の空オブジェクトに壁を格納し、複製しながら配置していきます。</p>



<figure class="wp-block-image size-full is-resized"><a href="https://d9m.one/wp-content/uploads/2022/07/TandH_031.png"><img decoding="async" src="https://d9m.one/wp-content/uploads/2022/07/TandH_031.png" alt="" class="wp-image-854" width="658" height="475" srcset="https://d9m.one/wp-content/uploads/2022/07/TandH_031.png 877w, https://d9m.one/wp-content/uploads/2022/07/TandH_031-300x217.png 300w, https://d9m.one/wp-content/uploads/2022/07/TandH_031-768x554.png 768w" sizes="(max-width: 658px) 100vw, 658px" /></a><figcaption>壁配置</figcaption></figure>



<p class="has-medium-font-size"><strong>・空オブジェクト作成</strong></p>



<ol class="wp-block-list"><li>ヒエラルキー左上の「＋」をクリック</li><li>「空のオブジェクトを作成」をクリック</li><li>「Blocks」と入力し、ENTERキーを押す</li></ol>



<p class="has-medium-font-size"><strong>・位置スケールリセット</strong></p>



<ol class="wp-block-list"><li>インスペクターのTransformにある縦の三点リーダーをクリック</li><li>リセットをクリック</li></ol>



<p class="has-medium-font-size"><strong>・階層設定</strong></p>



<ol class="wp-block-list"><li>ヒエラルキーの「Block」をヒエラルキーの「Blocks」にドラッグ＆ドロップ</li></ol>



<p class="has-medium-font-size"><strong>・位置設定</strong></p>



<ol class="wp-block-list"><li>インスペクターのTransformにある位置を(0, 0, 9)とする</li></ol>



<p class="has-medium-font-size"><strong>・複製、位置設定</strong></p>



<ol class="wp-block-list"><li>ヒエラルキーの「Blocks&gt;Block」をクリック</li><li>CTRLを押しながらDキーを押す</li><li>インスペクターのTransformにある位置を(0, 0, 7)とする</li><li>ヒエラルキーの「Blocks&gt;Block (1)」をクリック</li><li>CTRLを押しながらDキーを押す</li><li>インスペクターのTransformにある位置を(0, 0, 6)とする</li><li>ヒエラルキーの「Blocks&gt;Block (2)」をクリック</li><li>CTRLを押しながらDキーを押す</li><li>インスペクターのTransformにある位置を(0, 0, 5)とする</li><li>ヒエラルキーの「Blocks&gt;Block (3)」をクリック</li><li>CTRLを押しながらDキーを押す</li><li>インスペクターのTransformにある位置を(0, 0, 4)とする</li><li>ヒエラルキーの「Blocks&gt;Block (4)」をクリック</li><li>CTRLを押しながらDキーを押す</li><li>インスペクターのTransformにある位置を(0, 0, 3)とする</li><li>ヒエラルキーの「Blocks&gt;Block (5)」をクリック</li><li>CTRLを押しながらDキーを押す</li><li>インスペクターのTransformにある位置を(0, 0, 2)とする</li><li>ヒエラルキーの「Blocks&gt;Block (6)」をクリック</li><li>CTRLを押しながらDキーを押す</li><li>インスペクターのTransformにある位置を(0, 0, 0)とする</li></ol>



<ol class="wp-block-list"><li>ヒエラルキーの「Blocks&gt;Block (7)」をクリック</li><li>CTRLを押しながらDキーを押す</li><li>インスペクターのTransformにある位置を(2, 0, 0)とする</li><li>ヒエラルキーの「Blocks&gt;Block (8)」をクリック</li><li>CTRLを押しながらDキーを押す</li><li>インスペクターのTransformにある位置を(3, 0, 0)とする</li><li>ヒエラルキーの「Blocks&gt;Block (9)」をクリック</li><li>CTRLを押しながらDキーを押す</li><li>インスペクターのTransformにある位置を(4, 0, 0)とする</li><li>ヒエラルキーの「Blocks&gt;Block (10)」をクリック</li><li>CTRLを押しながらDキーを押す</li><li>インスペクターのTransformにある位置を(5, 0, 0)とする</li><li>ヒエラルキーの「Blocks&gt;Block (11)」をクリック</li><li>CTRLを押しながらDキーを押す</li><li>インスペクターのTransformにある位置を(6, 0, 0)とする</li><li>ヒエラルキーの「Blocks&gt;Block (12)」をクリック</li><li>CTRLを押しながらDキーを押す</li><li>インスペクターのTransformにある位置を(7, 0, 0)とする</li><li>ヒエラルキーの「Blocks&gt;Block (13)」をクリック</li><li>CTRLを押しながらDキーを押す</li><li>インスペクターのTransformにある位置を(9, 0, 0)とする</li></ol>



<ol class="wp-block-list"><li>ヒエラルキーの「Blocks&gt;Block (14)」をクリック</li><li>CTRLを押しながらDキーを押す</li><li>インスペクターのTransformにある位置を(9, 0, 2)とする</li><li>ヒエラルキーの「Blocks&gt;Block (15)」をクリック</li><li>CTRLを押しながらDキーを押す</li><li>インスペクターのTransformにある位置を(9, 0, 3)とする</li><li>ヒエラルキーの「Blocks&gt;Block (16)」をクリック</li><li>CTRLを押しながらDキーを押す</li><li>インスペクターのTransformにある位置を(9, 0, 4)とする</li><li>ヒエラルキーの「Blocks&gt;Block (17)」をクリック</li><li>CTRLを押しながらDキーを押す</li><li>インスペクターのTransformにある位置を(9, 0, 5)とする</li><li>ヒエラルキーの「Blocks&gt;Block (18)」をクリック</li><li>CTRLを押しながらDキーを押す</li><li>インスペクターのTransformにある位置を(9, 0, 6)とする</li><li>ヒエラルキーの「Blocks&gt;Block (19)」をクリック</li><li>CTRLを押しながらDキーを押す</li><li>インスペクターのTransformにある位置を(9, 0, 7)とする</li><li>ヒエラルキーの「Blocks&gt;Block (20)」をクリック</li><li>CTRLを押しながらDキーを押す</li><li>インスペクターのTransformにある位置を(9, 0, 9)とする</li></ol>



<ol class="wp-block-list"><li>ヒエラルキーの「Blocks&gt;Block (21)」をクリック</li><li>CTRLを押しながらDキーを押す</li><li>インスペクターのTransformにある位置を(7, 0, 9)とする</li><li>ヒエラルキーの「Blocks&gt;Block (22)」をクリック</li><li>CTRLを押しながらDキーを押す</li><li>インスペクターのTransformにある位置を(3, 0, 9)とする</li><li>ヒエラルキーの「Blocks&gt;Block (23)」をクリック</li><li>CTRLを押しながらDキーを押す</li><li>インスペクターのTransformにある位置を(2, 0, 9)とする</li></ol>



<p class="has-medium-font-size"><strong>・階層を閉じる</strong></p>



<ol class="wp-block-list"><li>ヒエラルキーの「Blocks」左にある「▼」をクリック</li></ol>



<p class="has-medium-font-size"><strong>・プロジェクト保存</strong></p>



<ol class="wp-block-list"><li>CTRLを押しながらSキーを押す</li></ol>
</div>
</div>



<div style="height:16px" aria-hidden="true" class="wp-block-spacer"></div>



<h3 class="has-background has-medium-font-size wp-block-heading" style="background-color:#e5f7fd"><span id="toc49">●ミスUI作成</span></h3>



<div style="height:16px" aria-hidden="true" class="wp-block-spacer"></div>



<div class="wp-block-group is-layout-flow wp-block-group-is-layout-flow">
<h4 class="wp-block-heading"><span id="toc50">▷ミスUI作成</span></h4>



<div class="wp-block-group is-layout-flow wp-block-group-is-layout-flow">
<p>タマがトゲ、もしくはヒシガタに衝突した時に「Miss!」というテキストを表示します。</p>



<figure class="wp-block-image size-full is-resized"><a href="https://d9m.one/wp-content/uploads/2022/07/TandH_032.png"><img decoding="async" src="https://d9m.one/wp-content/uploads/2022/07/TandH_032.png" alt="" class="wp-image-855" width="658" height="475" srcset="https://d9m.one/wp-content/uploads/2022/07/TandH_032.png 877w, https://d9m.one/wp-content/uploads/2022/07/TandH_032-300x217.png 300w, https://d9m.one/wp-content/uploads/2022/07/TandH_032-768x554.png 768w" sizes="(max-width: 658px) 100vw, 658px" /></a><figcaption>ミスUI作成（画像はオブジェクト無効化前）</figcaption></figure>



<p class="has-medium-font-size"><strong>・テキスト作成</strong></p>



<ol class="wp-block-list"><li>ヒエラルキー左上の「＋」をクリック</li><li>「UI＞テキスト &#8211; TextMeshPro」をクリック</li><li>「TextMiss」と入力し、ENTERキーを押す</li></ol>



<p class="has-medium-font-size"><strong>・TextMeshPro</strong>準備</p>



<ol class="wp-block-list"><li>TMP Importerの「Import TMP Essentials」をクリック</li><li>TMP Importerの右上にある「×」をクリック</li></ol>



<p class="has-medium-font-size"><strong>・UI位置設定</strong></p>



<ol class="wp-block-list"><li>インスペクターのRectTransform左上にあるアイコンをクリック</li><li>アンカープリセットの右下にある「Stretch &#8211; Stretch」をダブルクリック</li><li>インスペクターのRectTransform右上にある上下左右を全て「0」に設定</li></ol>



<p class="has-medium-font-size"><strong>・表示文字設定</strong></p>



<ol class="wp-block-list"><li>インスペクターのTextMeshProにある「Text Input&gt;テキスト入力」を「Miss!」に設定</li></ol>



<p class="has-medium-font-size"><strong>・文字装飾</strong></p>



<ol class="wp-block-list"><li>インスペクターのTextMeshProにある「Main Settings&gt;Font Style」にある「B」をクリック</li><li>インスペクターのTextMeshProにある「Main Settings&gt;Audo Size」のチェックボックスをクリック</li><li>インスペクターのTextMeshProにある「Main Settings&gt;Vertex Color」右のカラーバーをクリックし、色ダイアログの16進数を「FF0000」に設定</li><li>色ダイアログの右上にある「×」をクリック</li><li>インスペクターの「Shader&gt;Outline」左にあるチェックボックスをクリック</li><li>インスペクターの「Shader&gt;Outline」にある「Thickness」を「0.2」に設定</li></ol>



<p class="has-medium-font-size"><strong>・オブジェクト無効化</strong></p>



<ol class="wp-block-list"><li>インスペクター上部の左上にあるチェックボックスをクリック</li></ol>
</div>



<h4 class="wp-block-heading"><span id="toc51">▷ミス制御</span></h4>



<p>タマがトゲ、もしくはヒシガタとぶつかった時にミステキストを表示するようにCharCtrlを修正します。</p>



<figure class="wp-block-image size-full is-resized"><a href="https://d9m.one/wp-content/uploads/2022/07/TandH_033.png"><img decoding="async" src="https://d9m.one/wp-content/uploads/2022/07/TandH_033.png" alt="" class="wp-image-857" width="658" height="475" srcset="https://d9m.one/wp-content/uploads/2022/07/TandH_033.png 877w, https://d9m.one/wp-content/uploads/2022/07/TandH_033-300x217.png 300w, https://d9m.one/wp-content/uploads/2022/07/TandH_033-768x554.png 768w" sizes="(max-width: 658px) 100vw, 658px" /></a><figcaption>ミス制御</figcaption></figure>



<div class="wp-block-group is-layout-flow wp-block-group-is-layout-flow">
<p class="has-medium-font-size"><strong>・スクリプト編集開始</strong></p>



<ol class="wp-block-list"><li>プロジェクトの「Assets&gt;CharCtrl」をダブルクリック</li></ol>



<p class="has-medium-font-size"><strong>・スクリプト変数定義</strong></p>



<ol class="wp-block-list"><li>クラス定義内の先頭に以下の変数を追加</li></ol>



<div class="hcb_wrap"><pre class="prism line-numbers lang-csharp" data-file="CharCtrl.cs" data-lang="C#"><code>    public GameObject TextMiss;         // ミスUI
</code></pre></div>



<p class="has-medium-font-size"><strong>・スクリプト関数修正</strong></p>



<ol class="wp-block-list"><li>「タマとヒシガタの位置が同じだった場合」の条件内にある「タマとヒシガタを削除」前に「ミスUIを有効化」する以下の処理を追加</li></ol>



<div class="hcb_wrap"><pre class="prism line-numbers lang-csharp" data-file="CharCtrl.cs" data-lang="C#"><code>                // ミスUIを有効化
                TextMiss.SetActive(true);
</code></pre></div>



<p class="has-medium-font-size"><strong>・スクリプト関数修正</strong></p>



<ol class="wp-block-list"><li>「トゲと重なったら自分とトゲを削除」の条件内の先頭に「自分がタマだった場合、ミスUIを有効化」する処理を追加</li></ol>



<div class="hcb_wrap"><pre class="prism line-numbers lang-csharp" data-file="CharCtrl.cs" data-lang="C#"><code>            // 自分がタマだった場合、ミスUIを有効化
            if (tag == &quot;Player&quot;)
            {
                TextMiss.SetActive(true);
            }
</code></pre></div>



<p class="has-medium-font-size"><strong>・スクリプト保存</strong></p>



<ol class="wp-block-list"><li>CTRLを押しながらSキーを押す</li></ol>



<p class="has-medium-font-size"><strong>・Unityに戻ってスクリプトをビルド</strong></p>



<ol class="wp-block-list"><li>Unityエディタのタイトルをクリック</li></ol>



<p class="has-medium-font-size"><strong>・オブジェクト割り当て</strong></p>



<ol class="wp-block-list"><li>ヒエラルキーの「Tama」をクリック</li><li>ヒエラルキーの「Canvas&gt;TextMiss」をインスペクターの「Char Ctrl (スクリプト)&gt;Text Miss」右の参照ボックスにドラッグ＆ドロップ</li></ol>



<p class="has-medium-font-size"><strong>・プロジェクト保存</strong></p>



<ol class="wp-block-list"><li>CTRLを押しながらSキーを押す</li></ol>
</div>



<h4 class="wp-block-heading"><span id="toc52">▷動作確認</span></h4>



<div class="wp-block-group is-layout-flow wp-block-group-is-layout-flow">
<p>ミスした時にミステキストが表示されるかどうか、プレビューして確認します。</p>



<figure class="wp-block-image size-full is-resized"><a href="https://d9m.one/wp-content/uploads/2022/07/TandH_034.png"><img decoding="async" src="https://d9m.one/wp-content/uploads/2022/07/TandH_034.png" alt="" class="wp-image-859" width="658" height="475" srcset="https://d9m.one/wp-content/uploads/2022/07/TandH_034.png 877w, https://d9m.one/wp-content/uploads/2022/07/TandH_034-300x217.png 300w, https://d9m.one/wp-content/uploads/2022/07/TandH_034-768x554.png 768w" sizes="(max-width: 658px) 100vw, 658px" /></a><figcaption>動作確認</figcaption></figure>



<p class="has-medium-font-size"><strong>・プレビュー開始</strong></p>



<ol class="wp-block-list"><li>エディタ上中央の「▶」をクリック</li></ol>



<p class="has-medium-font-size"><strong>・動作確認</strong></p>



<ol class="wp-block-list"><li>ミスした時にミステキストが表示されるかどうか確認</li></ol>



<p class="has-medium-font-size"><strong>・プレビュー終了</strong></p>



<ol class="wp-block-list"><li>エディタ上中央の「▶」をクリック</li></ol>
</div>
</div>



<div style="height:16px" aria-hidden="true" class="wp-block-spacer"></div>



<h3 class="has-background has-medium-font-size wp-block-heading" style="background-color:#e5f7fd"><span id="toc53">●クリアUI作成</span></h3>



<div style="height:16px" aria-hidden="true" class="wp-block-spacer"></div>



<div class="wp-block-group is-layout-flow wp-block-group-is-layout-flow">
<h4 class="wp-block-heading"><span id="toc54">▷クリアUI作成</span></h4>



<div class="wp-block-group is-layout-flow wp-block-group-is-layout-flow">
<p>タマがゴールに衝突した時に「Clear!」というテキストを表示します。</p>



<figure class="wp-block-image size-full is-resized"><a href="https://d9m.one/wp-content/uploads/2022/07/TandH_035.png"><img decoding="async" src="https://d9m.one/wp-content/uploads/2022/07/TandH_035.png" alt="" class="wp-image-861" width="658" height="475" srcset="https://d9m.one/wp-content/uploads/2022/07/TandH_035.png 877w, https://d9m.one/wp-content/uploads/2022/07/TandH_035-300x217.png 300w, https://d9m.one/wp-content/uploads/2022/07/TandH_035-768x554.png 768w" sizes="(max-width: 658px) 100vw, 658px" /></a><figcaption>クリアUI作成（画像はオブジェクト無効化前）</figcaption></figure>



<p class="has-medium-font-size"><strong>・オブジェクト複製</strong></p>



<ol class="wp-block-list"><li>ヒエラルキーの「Canvas&gt;TextMiss」をクリック</li><li>CTRLを押しながらDキーを押す</li></ol>



<p class="has-medium-font-size"><strong>・オブジェクト名変更</strong></p>



<ol class="wp-block-list"><li>F2キーを押して「TextClear」と入力し、ENTERを押す</li></ol>



<p class="has-medium-font-size"><strong>・オブジェクト有効化</strong></p>



<ol class="wp-block-list"><li>インスペクター上部の左上にあるチェックボックスをクリック</li></ol>



<p class="has-medium-font-size"><strong><strong>・表示文字設定</strong></strong></p>



<ol class="wp-block-list"><li>インスペクターのTextMeshProにある「Text Input&gt;テキスト入力」を「Clear!」に設定</li></ol>



<p class="has-medium-font-size"><strong><strong>・文字装飾</strong></strong></p>



<ol class="wp-block-list"><li>インスペクターのTextMeshProにある「Main Settings&gt;Vertex Color」右のカラーバーをクリックし、色ダイアログの16進数を「00FFFF」に設定</li><li>色ダイアログの右上にある「×」をクリック</li></ol>



<p class="has-medium-font-size"><strong><strong><strong>・オブジェクト無効化</strong></strong></strong></p>



<ol class="wp-block-list"><li>インスペクター上部の左上にあるチェックボックスをクリック</li></ol>
</div>



<h4 class="wp-block-heading"><span id="toc55">▷クリア制御</span></h4>



<p>タマがゴールと衝突した時にクリアテキストを表示するようにCharCtrlを修正します。</p>



<figure class="wp-block-image size-full is-resized"><a href="https://d9m.one/wp-content/uploads/2022/07/TandH_036.png"><img decoding="async" src="https://d9m.one/wp-content/uploads/2022/07/TandH_036.png" alt="" class="wp-image-862" width="658" height="475" srcset="https://d9m.one/wp-content/uploads/2022/07/TandH_036.png 877w, https://d9m.one/wp-content/uploads/2022/07/TandH_036-300x217.png 300w, https://d9m.one/wp-content/uploads/2022/07/TandH_036-768x554.png 768w" sizes="(max-width: 658px) 100vw, 658px" /></a><figcaption>クリア制御</figcaption></figure>



<div class="wp-block-group is-layout-flow wp-block-group-is-layout-flow">
<p class="has-medium-font-size"><strong><strong><strong>・スクリプト編集開始</strong></strong></strong></p>



<ol class="wp-block-list"><li>プロジェクトの「Assets&gt;CharCtrl」をダブルクリック</li></ol>



<p class="has-medium-font-size"><strong><strong><strong>・スクリプト変数定義</strong></strong></strong></p>



<ol class="wp-block-list"><li>ミスUIの定義の後に以下の変数を追加</li></ol>



<div class="hcb_wrap"><pre class="prism line-numbers lang-csharp" data-file="CharCtrl.cs" data-lang="C#"><code>    public GameObject TextClear;        // クリアUI
</code></pre></div>



<p class="has-medium-font-size"><strong><strong><strong>・スクリプト関数修正</strong></strong></strong></p>



<ol class="wp-block-list"><li>「自分がタマで、かつゴールと重なった場合」の条件内処理の先頭に以下のスクリプトを追加</li></ol>



<div class="hcb_wrap"><pre class="prism line-numbers lang-csharp" data-file="CharCtrl.cs" data-lang="C#"><code>            // クリアUIを有効化
            TextClear.SetActive(true);
</code></pre></div>



<p class="has-medium-font-size"><strong><strong><strong><strong>・スクリプト保存</strong></strong></strong></strong></p>



<ol class="wp-block-list"><li>CTRLを押しながらSキーを押す</li></ol>



<p class="has-medium-font-size"><strong><strong><strong><strong><strong><strong>・Unityに戻ってスクリプトをビルド</strong></strong></strong></strong></strong></strong></p>



<ol class="wp-block-list"><li>Unityエディタのタイトルをクリック</li></ol>



<p class="has-medium-font-size"><strong><strong><strong><strong><strong><strong>・オブジェクト割り当て</strong></strong></strong></strong></strong></strong></p>



<ol class="wp-block-list"><li>ヒエラルキーの「Tama」をクリック</li><li>ヒエラルキーの「Canvas&gt;TextClear」をインスペクターの「Char Ctrl (スクリプト)&gt;Text Clear」右の参照ボックスにドラッグ＆ドロップ</li></ol>



<p class="has-medium-font-size"><strong><strong><strong><strong><strong>・プロジェクト保存</strong></strong></strong></strong></strong></p>



<ol class="wp-block-list"><li>CTRLを押しながらSキーを押す</li></ol>
</div>



<h4 class="wp-block-heading"><span id="toc56">▷動作確認</span></h4>



<div class="wp-block-group is-layout-flow wp-block-group-is-layout-flow">
<p>タマがゴールに衝突した時にクリアテキストが表示されるかどうか、プレビューして確認します。</p>



<figure class="wp-block-image size-full is-resized"><a href="https://d9m.one/wp-content/uploads/2022/07/TandH_037.png"><img decoding="async" src="https://d9m.one/wp-content/uploads/2022/07/TandH_037.png" alt="" class="wp-image-863" width="658" height="475" srcset="https://d9m.one/wp-content/uploads/2022/07/TandH_037.png 877w, https://d9m.one/wp-content/uploads/2022/07/TandH_037-300x217.png 300w, https://d9m.one/wp-content/uploads/2022/07/TandH_037-768x554.png 768w" sizes="(max-width: 658px) 100vw, 658px" /></a><figcaption>動作確認</figcaption></figure>



<p class="has-medium-font-size"><strong><strong><strong><strong><strong>・プレビュー開始</strong></strong></strong></strong></strong></p>



<ol class="wp-block-list"><li>エディタ上中央の「▶」をクリック</li></ol>



<p class="has-medium-font-size"><strong><strong><strong><strong><strong>・動作確認</strong></strong></strong></strong></strong></p>



<ol class="wp-block-list"><li>タマがゴールに衝突した時にクリアテキストが表示されるかどうか確認</li></ol>



<p class="has-medium-font-size"><strong>・プレビュー終了</strong></p>



<ol class="wp-block-list"><li>エディタ上中央の「▶」をクリック</li></ol>
</div>
</div>



<div style="height:16px" aria-hidden="true" class="wp-block-spacer"></div>



<p class="has-text-align-center" style="font-size:80px"><strong>完成！</strong></p>



<div style="height:16px" aria-hidden="true" class="wp-block-spacer"></div>
<p>投稿 <a href="https://d9m.one/proc_tandh_full/">【基本操作】タマあんどヒシガタ～完全手順【パズル】</a> は <a href="https://d9m.one">だくまたゲーム制作ブログ</a> に最初に表示されました。</p>
]]></content:encoded>
					
					<wfw:commentRss>https://d9m.one/proc_tandh_full/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>【基本操作】ピンボール～２／２　オブジェクト機能【アクション】</title>
		<link>https://d9m.one/proc_pinball2/</link>
					<comments>https://d9m.one/proc_pinball2/#respond</comments>
		
		<dc:creator><![CDATA[だくまた]]></dc:creator>
		<pubDate>Tue, 05 Jul 2022 12:36:57 +0000</pubDate>
				<category><![CDATA[Unity]]></category>
		<category><![CDATA[基本操作]]></category>
		<category><![CDATA[チュートリアル]]></category>
		<guid isPermaLink="false">https://d9m.one/?p=998</guid>

					<description><![CDATA[<p>●プレイヤー制御 ▷スクリプト整理 スクリプト格納用のフォルダを作成します。 プロジェクト左上の「＋」をクリックし、「フォルダー」をクリック 「Scripts」と入力し、ENTERキーを押す ▷玉物理設定 玉にRigid [&#8230;]</p>
<p>投稿 <a href="https://d9m.one/proc_pinball2/">【基本操作】ピンボール～２／２　オブジェクト機能【アクション】</a> は <a href="https://d9m.one">だくまたゲーム制作ブログ</a> に最初に表示されました。</p>
]]></description>
										<content:encoded><![CDATA[
<div style="height:16px" aria-hidden="true" class="wp-block-spacer"></div>



<h3 class="has-background has-medium-font-size wp-block-heading" style="background-color:#e5f7fd"><span id="toc1">●プレイヤー制御</span></h3>



<div style="height:16px" aria-hidden="true" class="wp-block-spacer"></div>



<div class="wp-block-group is-layout-flow wp-block-group-is-layout-flow">
<h4 class="wp-block-heading"><span id="toc2">▷スクリプト整理</span></h4>



<p>スクリプト格納用のフォルダを作成します。</p>



<figure class="wp-block-image size-full is-resized"><a href="https://d9m.one/wp-content/uploads/2022/07/Pinball_021.png"><img decoding="async" src="https://d9m.one/wp-content/uploads/2022/07/Pinball_021.png" alt="" class="wp-image-614" width="658" height="475" srcset="https://d9m.one/wp-content/uploads/2022/07/Pinball_021.png 877w, https://d9m.one/wp-content/uploads/2022/07/Pinball_021-300x217.png 300w, https://d9m.one/wp-content/uploads/2022/07/Pinball_021-768x554.png 768w" sizes="(max-width: 658px) 100vw, 658px" /></a><figcaption>【スクリプト整理】スクリプト格納用のフォルダを作成</figcaption></figure>



<ol class="wp-block-list"><li>プロジェクト左上の「＋」をクリックし、「フォルダー」をクリック</li><li>「Scripts」と入力し、ENTERキーを押す</li></ol>



<h4 class="wp-block-heading"><span id="toc3">▷玉物理設定</span></h4>



<p>玉にRigidbody「質量(0.7)、衝突判定(連続的かつ動的)、Z位置固定」として割り当て、物理マテリアルを弾性力(0.3)として割り当てます。</p>



<figure class="wp-block-image size-full is-resized"><a href="https://d9m.one/wp-content/uploads/2022/07/Pinball_022.png"><img decoding="async" src="https://d9m.one/wp-content/uploads/2022/07/Pinball_022.png" alt="" class="wp-image-615" width="658" height="475" srcset="https://d9m.one/wp-content/uploads/2022/07/Pinball_022.png 877w, https://d9m.one/wp-content/uploads/2022/07/Pinball_022-300x217.png 300w, https://d9m.one/wp-content/uploads/2022/07/Pinball_022-768x554.png 768w" sizes="(max-width: 658px) 100vw, 658px" /></a><figcaption>【玉物理設定】玉にRigidbody「質量(0.7)、衝突判定(連続的かつ動的)、Z位置固定」として割り当て、物理マテリアルを弾性力(0.3)として割り当てる</figcaption></figure>



<ol class="wp-block-list"><li>ヒエラルキーの「Ball」をクリック</li><li>インスペクターの「コンポーネントを追加」をクリックし、Physics＞Rigidbodyをクリック</li><li>インスペクターの「Rigidbody＞質量」を(0.7)に設定</li><li>インスペクターの「Rigidbody＞衝突判定」を(連続的かつ動的)に設定</li><li>インスペクターの「Rigidbody＞Constraints＞位置を固定＞Z」をチェック</li><li>プロジェクトの「Assets」を右クリックし、「作成＞物理マテリアル」をクリック</li><li>「Friction」と入力し、ENTERキーを押す</li><li>インスペクターの弾性力を(0.3)に設定</li><li>プロジェクトの「Friction」をヒエラルキーの「Ball」にドラッグ＆ドロップ</li><li>CTRLキーを押しながらSキーを押す</li></ol>



<h4 class="wp-block-heading"><span id="toc4">▷打ち出し器物理設定</span></h4>



<p>打ち出し器にRigidbodyを割り当て、Is Kinematic(あり)、衝突判定(連続的かつ動的)とします。</p>



<figure class="wp-block-image size-full is-resized"><a href="https://d9m.one/wp-content/uploads/2022/07/Pinball_023.png"><img decoding="async" src="https://d9m.one/wp-content/uploads/2022/07/Pinball_023.png" alt="" class="wp-image-616" width="658" height="475" srcset="https://d9m.one/wp-content/uploads/2022/07/Pinball_023.png 877w, https://d9m.one/wp-content/uploads/2022/07/Pinball_023-300x217.png 300w, https://d9m.one/wp-content/uploads/2022/07/Pinball_023-768x554.png 768w" sizes="(max-width: 658px) 100vw, 658px" /></a><figcaption>【打ち出し器物理設定】打ち出し器にRigidbodyを割り当て、Is Kinematic(あり)、衝突判定(連続的かつ動的)とする</figcaption></figure>



<ol class="wp-block-list"><li>ヒエラルキーの「Plunger」をクリック</li><li>インスペクターの「コンポーネントを追加」をクリックし、Physics＞Rigidbodyをクリック</li><li>インスペクターの「Rigidbody＞Is Kinematic」をチェック</li><li>インスペクターの「Rigidbody＞衝突判定」を(連続的かつ動的)に設定</li><li>CTRLキーを押しながらSキーを押す</li></ol>



<h4 class="wp-block-heading"><span id="toc5">▷制御スクリプト作成</span></h4>



<p>スクリプト「GameManager」を作成し、玉に割り当てます。</p>



<figure class="wp-block-image size-full is-resized"><a href="https://d9m.one/wp-content/uploads/2022/07/Pinball_024.png"><img decoding="async" src="https://d9m.one/wp-content/uploads/2022/07/Pinball_024.png" alt="" class="wp-image-619" width="658" height="475" srcset="https://d9m.one/wp-content/uploads/2022/07/Pinball_024.png 877w, https://d9m.one/wp-content/uploads/2022/07/Pinball_024-300x217.png 300w, https://d9m.one/wp-content/uploads/2022/07/Pinball_024-768x554.png 768w" sizes="(max-width: 658px) 100vw, 658px" /></a><figcaption>【打ち出し器制御】スクリプト「GameManager」を作成し、玉に割り当てる</figcaption></figure>



<ol class="wp-block-list"><li>プロジェクトの「Assets＞Scripts」を右クリックし、「作成＞C# スクリプト」をクリック</li><li>「GameManager」と入力し、ENTERキーを押す</li><li>プロジェクトの「GameManager」をヒエラルキーの「Ball」にドラッグ＆ドロップ</li><li>CTRLキーを押しながらSキーを押す</li></ol>



<h4 class="wp-block-heading"><span id="toc6">▷打ち出し器制御</span></h4>



<p>スペースを押している間は1フレームに0.5の速度で最大0まで上昇、離している間は1フレームに1の速度で最小-3.5まで下降させます。</p>



<ol class="wp-block-list"><li>プロジェクトの「Assets＞Scripts＞GameManager」をダブルクリック</li><li>スクリプトを以下のように記述</li></ol>



<div class="hcb_wrap"><pre class="prism line-numbers lang-plain" data-file="GameManager.cs"><code>using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class GameManager : MonoBehaviour
{
    public GameObject plunger;

    float plungerY = 3.5f;

    // Start is called before the first frame update
    void Start()
    {

    }

    // Update is called once per frame
    void Update()
    {
        Vector3 pos = plunger.transform.position;
        if (Input.GetAxis(&quot;Jump&quot;) &lt;= 0)
        {
            plungerY = Mathf.Clamp(plungerY + 0.5f, -3.5f, 0);
            pos.y = plungerY;
        }
        if (Input.GetAxis(&quot;Jump&quot;) &gt; 0)
        {
            plungerY = Mathf.Clamp(plungerY - 1, -3.5f, 0);
            pos.y = plungerY;
        }
        Rigidbody rb = plunger.GetComponent&lt;Rigidbody&gt;();
        rb.MovePosition(pos);
    }
}</code></pre></div>



<h4 class="wp-block-heading"><span id="toc7">▷打ち出し器割り当て</span></h4>



<p>GameManagerの参照に打ち出し器を割り当てます。</p>



<figure class="wp-block-image size-full is-resized"><a href="https://d9m.one/wp-content/uploads/2022/07/Pinball_025.png"><img decoding="async" src="https://d9m.one/wp-content/uploads/2022/07/Pinball_025.png" alt="" class="wp-image-620" width="658" height="475" srcset="https://d9m.one/wp-content/uploads/2022/07/Pinball_025.png 877w, https://d9m.one/wp-content/uploads/2022/07/Pinball_025-300x217.png 300w, https://d9m.one/wp-content/uploads/2022/07/Pinball_025-768x554.png 768w" sizes="(max-width: 658px) 100vw, 658px" /></a><figcaption>【打ち出し器割り当て】GameManagerの参照に打ち出し器を割り当てる</figcaption></figure>



<ol class="wp-block-list"><li>ヒエラルキーの「Ball」をクリック</li><li>ヒエラルキーの「Plumger」をインスペクターの「GameManager＞Plunger」にドラッグ＆ドロップ</li><li>CTRLキーを押しながらSキーを押す</li></ol>



<h4 class="wp-block-heading"><span id="toc8">▷打ち出し器制御確認</span></h4>



<p>スペースキーで打ち出し器を操作できることを確認します。</p>



<figure class="wp-block-image size-full is-resized"><a href="https://d9m.one/wp-content/uploads/2022/07/Pinball_026.png"><img decoding="async" src="https://d9m.one/wp-content/uploads/2022/07/Pinball_026.png" alt="" class="wp-image-621" width="658" height="475" srcset="https://d9m.one/wp-content/uploads/2022/07/Pinball_026.png 877w, https://d9m.one/wp-content/uploads/2022/07/Pinball_026-300x217.png 300w, https://d9m.one/wp-content/uploads/2022/07/Pinball_026-768x554.png 768w" sizes="(max-width: 658px) 100vw, 658px" /></a><figcaption>【打ち出し器制御確認】スペースキーで打ち出し器を操作できることを確認</figcaption></figure>



<ol class="wp-block-list"><li>エディタ上中央の「▶」をクリック</li><li>スペースキーを押す</li><li>打ち出し器が手前に移動することを確認</li><li>スペースキーを離す</li><li>打ち出し器が元の場所に戻り、球が打ち出される事を確認</li><li>エディタ上中央の「▶」をクリック</li></ol>



<h4 class="wp-block-heading"><span id="toc9">▷フリッパー物理設定</span></h4>



<p>フリッパーにRigidbodyを割り当て、Is Kinematic(あり)、衝突判定(連続的かつ動的)とします。</p>



<figure class="wp-block-image size-full is-resized"><a href="https://d9m.one/wp-content/uploads/2022/07/Pinball_027.png"><img decoding="async" src="https://d9m.one/wp-content/uploads/2022/07/Pinball_027.png" alt="" class="wp-image-622" width="658" height="475" srcset="https://d9m.one/wp-content/uploads/2022/07/Pinball_027.png 877w, https://d9m.one/wp-content/uploads/2022/07/Pinball_027-300x217.png 300w, https://d9m.one/wp-content/uploads/2022/07/Pinball_027-768x554.png 768w" sizes="(max-width: 658px) 100vw, 658px" /></a><figcaption>【フリッパー物理設定】フリッパーにRigidbodyを割り当て、Is Kinematic(あり)、衝突判定(連続的かつ動的)とする</figcaption></figure>



<ol class="wp-block-list"><li>プロジェクトの「Assets＞Prefabs＞Flipper」をダブルクリック</li><li>インスペクターの「コンポーネントを追加」をクリックし、Physics＞Rigidbodyをクリック</li><li>インスペクターの「Rigidbody＞Is Kinematic」をチェック</li><li>インスペクターの「Rigidbody＞衝突判定」を(連続的かつ動的)に設定</li><li>ヒエラルキーの左上にある「＜」をクリック</li></ol>



<ol class="wp-block-list"><li>プロジェクトの「Assets＞Scripts＞GameManager」をダブルクリック</li><li>スクリプトを以下のように記述</li></ol>



<h4 class="wp-block-heading"><span id="toc10">▷フリッパー制御</span></h4>



<p>以下の仕様でスクリプトを記述します。</p>



<ul class="wp-block-list"><li>左クリックで左フリッパー、右クリックで右フリッパーをZ軸を1フレーム16度の速度で30度まで動かす</li><li>押されていない時はZ軸を1フレーム16度の速度で-18度まで動かす</li></ul>



<div class="hcb_wrap"><pre class="prism line-numbers lang-plain" data-file="GameManager.cs"><code>using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class GameManager : MonoBehaviour
{
    public GameObject plunger;
    public GameObject flipperL;
    public GameObject flipperR;

    float plungerY = 3.5f;
    float[] angle = {0, 0};

    // Start is called before the first frame update
    void Start()
    {

    }

    // Update is called once per frame
    void Update()
    {
        Vector3 pos = plunger.transform.position;
        if (Input.GetAxis(&quot;Jump&quot;) &lt;= 0)
        {
            plungerY = Mathf.Clamp(plungerY + 0.5f, -3.5f, 0);
            pos.y = plungerY;
        }
        if (Input.GetAxis(&quot;Jump&quot;) &gt; 0)
        {
            plungerY = Mathf.Clamp(plungerY - 1, -3.5f, 0);
            pos.y = plungerY;
        }
        Rigidbody rb = plunger.GetComponent&lt;Rigidbody&gt;();
        rb.MovePosition(pos);

        FlipAction(0);
        FlipAction(1);
    }

    void FlipAction(int button)
    {
        if (Input.GetMouseButton(button) == true)
        {
            angle[button] += 16;
        }
        else
        {
            angle[button] -= 16;
        }
        angle[button] = Mathf.Clamp(angle[button], -18, 30);

        GameObject flipper;
        if (button == 0)
        {
            flipper = flipperL;
        }
        else
        {
            flipper = flipperR;
        }
        Rigidbody rb = flipper.GetComponent&lt;Rigidbody&gt;();

        Vector3 rot = flipper.transform.rotation.eulerAngles;
        rot.z = angle[button];
        rb.MoveRotation(Quaternion.Euler(rot));
    }
}</code></pre></div>



<h4 class="wp-block-heading"><span id="toc11">▷フリッパー割り当て</span></h4>



<p>GameManagerの参照にフリッパーを割り当てます。</p>



<figure class="wp-block-image size-full is-resized"><a href="https://d9m.one/wp-content/uploads/2022/07/Pinball_028-1.png"><img decoding="async" src="https://d9m.one/wp-content/uploads/2022/07/Pinball_028-1.png" alt="" class="wp-image-627" width="658" height="475" srcset="https://d9m.one/wp-content/uploads/2022/07/Pinball_028-1.png 877w, https://d9m.one/wp-content/uploads/2022/07/Pinball_028-1-300x217.png 300w, https://d9m.one/wp-content/uploads/2022/07/Pinball_028-1-768x554.png 768w" sizes="(max-width: 658px) 100vw, 658px" /></a><figcaption>【フリッパー割り当て】GameManagerの参照にフリッパーを割り当てる</figcaption></figure>



<ol class="wp-block-list"><li>ヒエラルキーの「Ball」をクリック</li><li>ヒエラルキーの「FlipperL」をインスペクターの「GameManager＞FlipperL」にドラッグ＆ドロップ</li><li>ヒエラルキーの「FlipperR」をインスペクターの「GameManager＞FlipperR」にドラッグ＆ドロップ</li><li>CTRLキーを押しながらSキーを押す</li></ol>



<h4 class="wp-block-heading"><span id="toc12">▷フリッパー制御確認</span></h4>



<p>マウスクリックでフリッパーを操作できることを確認します。</p>



<figure class="wp-block-image size-full is-resized"><a href="https://d9m.one/wp-content/uploads/2022/07/Pinball_029-1.png"><img decoding="async" src="https://d9m.one/wp-content/uploads/2022/07/Pinball_029-1.png" alt="" class="wp-image-628" width="658" height="475" srcset="https://d9m.one/wp-content/uploads/2022/07/Pinball_029-1.png 877w, https://d9m.one/wp-content/uploads/2022/07/Pinball_029-1-300x217.png 300w, https://d9m.one/wp-content/uploads/2022/07/Pinball_029-1-768x554.png 768w" sizes="(max-width: 658px) 100vw, 658px" /></a><figcaption>【フリッパー制御確認】マウスクリックでフリッパーを操作できることを確認</figcaption></figure>



<ol class="wp-block-list"><li>エディタ上中央の「▶」をクリック</li><li>ゲームビュー上でマウス左ボタンをクリック</li><li>左のフリッパーが動く事を確認</li><li>ゲームビュー上でマウス右ボタンをクリック</li><li>右のフリッパーが動く事を確認</li><li>エディタ上中央の「▶」をクリック</li></ol>
</div>



<h3 class="has-background has-medium-font-size wp-block-heading" style="background-color:#e5f7fd"><span id="toc13">●オブジェクト制御</span></h3>



<div style="height:16px" aria-hidden="true" class="wp-block-spacer"></div>



<div class="wp-block-group is-layout-flow wp-block-group-is-layout-flow">
<h4 class="wp-block-heading"><span id="toc14">▷ターゲット設定</span></h4>



<p>ターゲットをトリガーにし、タグ「Target」を作成して割り当てます。</p>



<figure class="wp-block-image size-full is-resized"><a href="https://d9m.one/wp-content/uploads/2022/07/Pinball_030.png"><img decoding="async" src="https://d9m.one/wp-content/uploads/2022/07/Pinball_030.png" alt="" class="wp-image-626" width="658" height="475" srcset="https://d9m.one/wp-content/uploads/2022/07/Pinball_030.png 877w, https://d9m.one/wp-content/uploads/2022/07/Pinball_030-300x217.png 300w, https://d9m.one/wp-content/uploads/2022/07/Pinball_030-768x554.png 768w" sizes="(max-width: 658px) 100vw, 658px" /></a><figcaption>【ターゲット設定】ターゲットをトリガーにし、タグ「Target」を作成して割り当てる</figcaption></figure>



<ol class="wp-block-list"><li>プロジェクトの「Assets＞Prefabs＞Target」をダブルクリック</li><li>インスペクターの「Box Collider＞トリガーにする」をチェック</li><li>ヒエラルキーの「Target」をクリック</li><li>インスペクターのドロップダウン「タグ」をクリックし、「タグを追加&#8230;」をクリック</li><li>インスペクターのタグ右下の「＋」をクリック</li><li>「Target」と入力し、ENTERキーを押す</li><li>ヒエラルキーの「Target」をクリック</li><li>インスペクターのドロップダウン「タグ」をクリックし、「Target」をクリック</li><li>ヒエラルキー左上の「＜」をクリック</li></ol>



<h4 class="wp-block-heading"><span id="toc15">▷ターゲット制御</span></h4>



<p>プロジェクトの「Scripts＞GameManager」をダブルクリックし、玉がターゲットに衝突したらターゲットが消えるようにスクリプトを記述します。</p>



<div class="hcb_wrap"><pre class="prism line-numbers lang-plain" data-file="GameManager.cs"><code>using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class GameManager : MonoBehaviour
{
    public GameObject plunger;
    public GameObject flipperL;
    public GameObject flipperR;

    float plungerY = 3.5f;
    float[] angle = {0, 0};

    // Start is called before the first frame update
    void Start()
    {

    }

    // Update is called once per frame
    void Update()
    {
        Vector3 pos = plunger.transform.position;
        if (Input.GetAxis(&quot;Jump&quot;) &lt;= 0)
        {
            plungerY = Mathf.Clamp(plungerY + 0.5f, -3.5f, 0);
            pos.y = plungerY;
        }
        if (Input.GetAxis(&quot;Jump&quot;) &gt; 0)
        {
            plungerY = Mathf.Clamp(plungerY - 1, -3.5f, 0);
            pos.y = plungerY;
        }
        Rigidbody rb = plunger.GetComponent&lt;Rigidbody&gt;();
        rb.MovePosition(pos);

        FlipAction(0);
        FlipAction(1);
    }

    void FlipAction(int button)
    {
        if (Input.GetMouseButton(button) == true)
        {
            angle[button] += 16;
        }
        else
        {
            angle[button] -= 16;
        }
        angle[button] = Mathf.Clamp(angle[button], -18, 30);

        GameObject flipper;
        if (button == 0)
        {
            flipper = flipperL;
        }
        else
        {
            flipper = flipperR;
        }
        Rigidbody rb = flipper.GetComponent&lt;Rigidbody&gt;();

        Vector3 rot = flipper.transform.rotation.eulerAngles;
        rot.z = angle[button];
        rb.MoveRotation(Quaternion.Euler(rot));
    }

    void OnTriggerEnter(Collider collider)
    {
        if (collider.gameObject.CompareTag(&quot;Target&quot;))
        {
            Destroy(collider.gameObject);
        }
    }
}</code></pre></div>



<h4 class="wp-block-heading"><span id="toc16">▷ターゲット制御確認</span></h4>



<p>玉がターゲットに衝突したらターゲットが消えることを確認します。</p>



<figure class="wp-block-image size-full is-resized"><a href="https://d9m.one/wp-content/uploads/2022/07/Pinball_031.png"><img decoding="async" src="https://d9m.one/wp-content/uploads/2022/07/Pinball_031.png" alt="" class="wp-image-629" width="658" height="475" srcset="https://d9m.one/wp-content/uploads/2022/07/Pinball_031.png 877w, https://d9m.one/wp-content/uploads/2022/07/Pinball_031-300x217.png 300w, https://d9m.one/wp-content/uploads/2022/07/Pinball_031-768x554.png 768w" sizes="(max-width: 658px) 100vw, 658px" /></a><figcaption>【ターゲット制御確認】玉がターゲットに衝突したらターゲットが消えることを確認</figcaption></figure>



<ol class="wp-block-list"><li>エディタ上中央の「▶」をクリック</li><li>玉をターゲットに衝突させる</li><li>ターゲットが消滅する事を確認</li><li>エディタ上中央の「▶」をクリック</li></ol>



<h4 class="wp-block-heading"><span id="toc17">▷バンパー物理設定</span></h4>



<p>バンパーにRigidbodyを割り当て、Is Kinematic(あり)、衝突判定(連続的かつ動的)とします。</p>



<figure class="wp-block-image size-full is-resized"><a href="https://d9m.one/wp-content/uploads/2022/07/Pinball_032.png"><img decoding="async" src="https://d9m.one/wp-content/uploads/2022/07/Pinball_032.png" alt="" class="wp-image-630" width="658" height="475" srcset="https://d9m.one/wp-content/uploads/2022/07/Pinball_032.png 877w, https://d9m.one/wp-content/uploads/2022/07/Pinball_032-300x217.png 300w, https://d9m.one/wp-content/uploads/2022/07/Pinball_032-768x554.png 768w" sizes="(max-width: 658px) 100vw, 658px" /></a><figcaption>【バンパー物理設定】バンパーにRigidbodyを割り当て、Is Kinematic(あり)、衝突判定(連続的かつ動的)とする</figcaption></figure>



<ol class="wp-block-list"><li>プロジェクトの「Assets＞Prefabs＞Bumper」をダブルクリック</li><li>インスペクターの「コンポーネントを追加」をクリックし、Physics＞Rigidbodyをクリック</li><li>インスペクターの「Rigidbody＞Is Kinematic」をチェック</li><li>インスペクターの「Rigidbody＞衝突判定」を(連続的かつ動的)に設定</li><li>ヒエラルキーの左上にある「＜」をクリック</li></ol>



<h4 class="wp-block-heading"><span id="toc18">▷バンパー認識</span></h4>



<p>タグ「Bumper」を作成し、バンパーに割り当てます。</p>



<figure class="wp-block-image size-full is-resized"><a href="https://d9m.one/wp-content/uploads/2022/07/Pinball_033.png"><img decoding="async" src="https://d9m.one/wp-content/uploads/2022/07/Pinball_033.png" alt="" class="wp-image-631" width="658" height="475" srcset="https://d9m.one/wp-content/uploads/2022/07/Pinball_033.png 877w, https://d9m.one/wp-content/uploads/2022/07/Pinball_033-300x217.png 300w, https://d9m.one/wp-content/uploads/2022/07/Pinball_033-768x554.png 768w" sizes="(max-width: 658px) 100vw, 658px" /></a><figcaption>【バンパー認識】タグ「Bumper」を作成し、バンパーに割り当てる</figcaption></figure>



<ol class="wp-block-list"><li>プロジェクトの「Assets＞Prefabs＞Bumper」をダブルクリック</li><li>ヒエラルキーの「Bumper」をクリック</li><li>インスペクターのドロップダウン「タグ」をクリックし、「タグを追加&#8230;」をクリック</li><li>インスペクターのタグ右下の「＋」をクリック</li><li>「Bumper」と入力し、ENTERキーを押す</li><li>ヒエラルキーの「Bumper」をクリック</li><li>インスペクターのドロップダウン「タグ」をクリックし、「Bumper」をクリック</li><li>ヒエラルキー左上の「＜」をクリック</li></ol>



<h4 class="wp-block-heading"><span id="toc19">▷バンパー制御</span></h4>



<p>プロジェクトの「Assets＞Scripts＞GameManager」をダブルクリックし、玉がバンパーに衝突したら弾かれるようにスクリプトを記述します。</p>



<div class="hcb_wrap"><pre class="prism line-numbers lang-plain" data-file="GameManager.cs"><code>using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class GameManager : MonoBehaviour
{
    public GameObject plunger;
    public GameObject flipperL;
    public GameObject flipperR;

    float plungerY = 3.5f;
    float[] angle = {0, 0};

    // Start is called before the first frame update
    void Start()
    {

    }

    // Update is called once per frame
    void Update()
    {
        Vector3 pos = plunger.transform.position;
        if (Input.GetAxis(&quot;Jump&quot;) &lt;= 0)
        {
            plungerY = Mathf.Clamp(plungerY + 0.5f, -3.5f, 0);
            pos.y = plungerY;
        }
        if (Input.GetAxis(&quot;Jump&quot;) &gt; 0)
        {
            plungerY = Mathf.Clamp(plungerY - 1, -3.5f, 0);
            pos.y = plungerY;
        }
        Rigidbody rb = plunger.GetComponent&lt;Rigidbody&gt;();
        rb.MovePosition(pos);

        FlipAction(0);
        FlipAction(1);
    }

    void FlipAction(int button)
    {
        if (Input.GetMouseButton(button) == true)
        {
            angle[button] += 16;
        }
        else
        {
            angle[button] -= 16;
        }
        angle[button] = Mathf.Clamp(angle[button], -18, 30);

        GameObject flipper;
        if (button == 0)
        {
            flipper = flipperL;
        }
        else
        {
            flipper = flipperR;
        }
        Rigidbody rb = flipper.GetComponent&lt;Rigidbody&gt;();

        Vector3 rot = flipper.transform.rotation.eulerAngles;
        rot.z = angle[button];
        rb.MoveRotation(Quaternion.Euler(rot));
    }

    void OnTriggerEnter(Collider collider)
    {
        if (collider.gameObject.CompareTag(&quot;Target&quot;))
        {
            Destroy(collider.gameObject);
        }
    }

    void OnCollisionEnter(Collision collision)
    {
        if (collision.gameObject.CompareTag(&quot;Bumper&quot;))
        {
            Vector3 dir = transform.position - collision.transform.position;
            Rigidbody rb = GetComponent&lt;Rigidbody&gt;();
            rb.AddForce(dir * 30, ForceMode.Impulse);
        }
    }
}</code></pre></div>



<h4 class="wp-block-heading"><span id="toc20">▷バンパー制御確認</span></h4>



<p>玉がバンパーに衝突したら弾かれる事を確認します。</p>



<figure class="wp-block-image size-full is-resized"><a href="https://d9m.one/wp-content/uploads/2022/07/Pinball_034.png"><img decoding="async" src="https://d9m.one/wp-content/uploads/2022/07/Pinball_034.png" alt="" class="wp-image-632" width="658" height="475" srcset="https://d9m.one/wp-content/uploads/2022/07/Pinball_034.png 877w, https://d9m.one/wp-content/uploads/2022/07/Pinball_034-300x217.png 300w, https://d9m.one/wp-content/uploads/2022/07/Pinball_034-768x554.png 768w" sizes="(max-width: 658px) 100vw, 658px" /></a><figcaption>【バンパー制御確認】玉がバンパーに衝突したら弾かれる事を確認</figcaption></figure>



<ol class="wp-block-list"><li>エディタ上中央の「▶」をクリック</li><li>バンパーに玉を衝突させる</li><li>玉が弾かれる事を確認</li><li>エディタ上中央の「▶」をクリック</li></ol>
</div>



<h3 class="has-background has-medium-font-size wp-block-heading" style="background-color:#e5f7fd"><span id="toc21">●ゲーム制御</span></h3>



<div style="height:16px" aria-hidden="true" class="wp-block-spacer"></div>



<div class="wp-block-group is-layout-flow wp-block-group-is-layout-flow">
<h4 class="wp-block-heading"><span id="toc22">▷ミスエリア認識</span></h4>



<p>ミスエリアにタグ「Finish」を割り当てます。</p>



<figure class="wp-block-image size-full is-resized"><a href="https://d9m.one/wp-content/uploads/2022/07/Pinball_035.png"><img decoding="async" src="https://d9m.one/wp-content/uploads/2022/07/Pinball_035.png" alt="" class="wp-image-633" width="658" height="475" srcset="https://d9m.one/wp-content/uploads/2022/07/Pinball_035.png 877w, https://d9m.one/wp-content/uploads/2022/07/Pinball_035-300x217.png 300w, https://d9m.one/wp-content/uploads/2022/07/Pinball_035-768x554.png 768w" sizes="(max-width: 658px) 100vw, 658px" /></a><figcaption>【ミスエリア認識】ミスエリアにタグ「Finish」を割り当てる</figcaption></figure>



<ol class="wp-block-list"><li>ヒエラルキーの「WallMiss」をクリック</li><li>インスペクターのドロップダウン「タグ」をクリックし、「Finish」をクリック</li><li>CTRLキーを押しながらSキーを押す</li></ol>



<h4 class="wp-block-heading"><span id="toc23">▷リスタート制御</span></h4>



<p>プロジェクトの「Assets＞Scripts＞GameManager」をダブルクリックし、玉がミスエリアに衝突したらリスタートするスクリプトを記述します。</p>



<div class="hcb_wrap"><pre class="prism line-numbers lang-plain" data-file="GameManager.cs"><code>using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;

public class GameManager : MonoBehaviour
{
    public GameObject plunger;
    public GameObject flipperL;
    public GameObject flipperR;

    float plungerY = 3.5f;
    float[] angle = {0, 0};

    // Start is called before the first frame update
    void Start()
    {

    }

    // Update is called once per frame
    void Update()
    {
        Vector3 pos = plunger.transform.position;
        if (Input.GetAxis(&quot;Jump&quot;) &lt;= 0)
        {
            plungerY = Mathf.Clamp(plungerY + 0.5f, -3.5f, 0);
            pos.y = plungerY;
        }
        if (Input.GetAxis(&quot;Jump&quot;) &gt; 0)
        {
            plungerY = Mathf.Clamp(plungerY - 1, -3.5f, 0);
            pos.y = plungerY;
        }
        Rigidbody rb = plunger.GetComponent&lt;Rigidbody&gt;();
        rb.MovePosition(pos);

        FlipAction(0);
        FlipAction(1);
    }

    void FlipAction(int button)
    {
        if (Input.GetMouseButton(button) == true)
        {
            angle[button] += 16;
        }
        else
        {
            angle[button] -= 16;
        }
        angle[button] = Mathf.Clamp(angle[button], -18, 30);

        GameObject flipper;
        if (button == 0)
        {
            flipper = flipperL;
        }
        else
        {
            flipper = flipperR;
        }
        Rigidbody rb = flipper.GetComponent&lt;Rigidbody&gt;();

        Vector3 rot = flipper.transform.rotation.eulerAngles;
        rot.z = angle[button];
        rb.MoveRotation(Quaternion.Euler(rot));
    }

    void OnTriggerEnter(Collider collider)
    {
        if (collider.gameObject.CompareTag(&quot;Target&quot;))
        {
            Destroy(collider.gameObject);
        }
    }

    void OnCollisionEnter(Collision collision)
    {
        if (collision.gameObject.CompareTag(&quot;Bumper&quot;))
        {
            Vector3 dir = transform.position - collision.transform.position;
            Rigidbody rb = GetComponent&lt;Rigidbody&gt;();
            rb.AddForce(dir * 30, ForceMode.Impulse);
        }
        if (collision.gameObject.CompareTag(&quot;Finish&quot;))
        {
            SceneManager.LoadScene(SceneManager.GetActiveScene().name);
        }
    }
}</code></pre></div>



<h4 class="wp-block-heading"><span id="toc24">▷リスタート確認</span></h4>



<p>玉がミスエリアに衝突したらゲームがやり直しになる事を確認します。</p>



<figure class="wp-block-image size-full is-resized"><a href="https://d9m.one/wp-content/uploads/2022/07/Pinball_036.png"><img decoding="async" src="https://d9m.one/wp-content/uploads/2022/07/Pinball_036.png" alt="" class="wp-image-634" width="658" height="475" srcset="https://d9m.one/wp-content/uploads/2022/07/Pinball_036.png 877w, https://d9m.one/wp-content/uploads/2022/07/Pinball_036-300x217.png 300w, https://d9m.one/wp-content/uploads/2022/07/Pinball_036-768x554.png 768w" sizes="(max-width: 658px) 100vw, 658px" /></a><figcaption>【リスタート確認】玉がミスエリアに衝突したらゲームがやり直しになる事を確認</figcaption></figure>



<ol class="wp-block-list"><li>エディタ上中央の「▶」をクリック</li><li>ミスエリアに玉を衝突させる</li><li>ゲームがやり直しになる事を確認</li><li>エディタ上中央の「▶」をクリック</li></ol>



<h4 class="wp-block-heading"><span id="toc25">▷クリアUI作成</span></h4>



<p>クリア用のUIテキストを非アクティブで配置します。</p>



<figure class="wp-block-image size-full is-resized"><a href="https://d9m.one/wp-content/uploads/2022/07/Pinball_037.png"><img decoding="async" src="https://d9m.one/wp-content/uploads/2022/07/Pinball_037.png" alt="" class="wp-image-635" width="658" height="475" srcset="https://d9m.one/wp-content/uploads/2022/07/Pinball_037.png 877w, https://d9m.one/wp-content/uploads/2022/07/Pinball_037-300x217.png 300w, https://d9m.one/wp-content/uploads/2022/07/Pinball_037-768x554.png 768w" sizes="(max-width: 658px) 100vw, 658px" /></a><figcaption>【クリアUI作成】クリア用のUIテキストを非アクティブで配置する</figcaption></figure>



<ol class="wp-block-list"><li>ヒエラルキー左上の「＋」をクリックし、「UI＞テキスト &#8211; TextMeshPro」をクリック</li><li>TMP Importerの「Import TMP Essentials」をクリック</li><li>TMP Importerを閉じる</li><li>ヒエラルキーの「Text (TMP)」をクリック</li><li>F2キーを押して「TextClear」と入力し、ENTERキーを押す</li><li>インスペクターを以下のように設定</li><li>・RectTransform左上のアイコン「アンカープリセット」をクリックし、右下の「stretch &#8211; stretch」をダブルクリック</li><li>・RectTransformの「上下左右」を(0, 0, 0, 0)に設定</li><li>・TextMeshProの「Text Input」にあるテキスト入力を「Clear!」に設定</li><li>・TextMeshProの「Main Settings&gt;Font Style」にある「B」をオンにする</li><li>・TextMeshProの「Main Settings&gt;Auto Size」にチェックを入れる</li><li>・TextMeshProの「Main Settings&gt;Vertex Color」右にあるカラーバーをクリックし、色ダイアログの16進数を「FFFF00」に設定</li><li>・色ダイアログの右上にある「×」をクリック</li><li>・TextMeshProの「Main Settings&gt;Alignment」にある「Center、Middle」をオンにする</li><li>・マテリアル設定にある「Outline」にチェックを入れる</li><li>・マテリアル設定にある「Outline&gt;Thickness」を(0.2)に設定</li><li>・マテリアル設定にある「Outline&gt;Color」にあるカラーバーをクリックし、HDRカラーのRを「255」に設定</li><li>・HDRカラーの右上にある「×」をクリック</li><li>インスペクター左上のチェックを外す</li><li>CTRLキーを押しながらSキーを押す</li></ol>



<h4 class="wp-block-heading"><span id="toc26">▷クリア制御</span></h4>



<p>プロジェクトの「Assets＞Scripts＞GameManager」をダブルクリックし、ターゲットを全て取得したらクリアUIを表示するスクリプトを記述します。</p>



<div class="hcb_wrap"><pre class="prism line-numbers lang-plain" data-file="GameManager.cs"><code>using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;

public class GameManager : MonoBehaviour
{
    public GameObject plunger;
    public GameObject flipperL;
    public GameObject flipperR;
    public GameObject uiClear;

    float plungerY = 3.5f;
    float[] angle = {0, 0};

    // Start is called before the first frame update
    void Start()
    {

    }

    // Update is called once per frame
    void Update()
    {
        GameObject[] targets = GameObject.FindGameObjectsWithTag(&quot;Target&quot;);
        if (targets.Length == 0)
        {
            uiClear.SetActive(true);
            Destroy(gameObject);
            return;
        }

        Vector3 pos = plunger.transform.position;
        if (Input.GetAxis(&quot;Jump&quot;) &lt;= 0)
        {
            plungerY = Mathf.Clamp(plungerY + 0.5f, -3.5f, 0);
            pos.y = plungerY;
        }
        if (Input.GetAxis(&quot;Jump&quot;) &gt; 0)
        {
            plungerY = Mathf.Clamp(plungerY - 1, -3.5f, 0);
            pos.y = plungerY;
        }
        Rigidbody rb = plunger.GetComponent&lt;Rigidbody&gt;();
        rb.MovePosition(pos);

        FlipAction(0);
        FlipAction(1);
    }

    void FlipAction(int button)
    {
        if (Input.GetMouseButton(button) == true)
        {
            angle[button] += 16;
        }
        else
        {
            angle[button] -= 16;
        }
        angle[button] = Mathf.Clamp(angle[button], -18, 30);

        GameObject flipper;
        if (button == 0)
        {
            flipper = flipperL;
        }
        else
        {
            flipper = flipperR;
        }
        Rigidbody rb = flipper.GetComponent&lt;Rigidbody&gt;();

        Vector3 rot = flipper.transform.rotation.eulerAngles;
        rot.z = angle[button];
        rb.MoveRotation(Quaternion.Euler(rot));
    }

    void OnTriggerEnter(Collider collider)
    {
        if (collider.gameObject.CompareTag(&quot;Target&quot;))
        {
            Destroy(collider.gameObject);
        }
    }

    void OnCollisionEnter(Collision collision)
    {
        if (collision.gameObject.CompareTag(&quot;Bumper&quot;))
        {
            Vector3 dir = transform.position - collision.transform.position;
            Rigidbody rb = GetComponent&lt;Rigidbody&gt;();
            rb.AddForce(dir * 30, ForceMode.Impulse);
        }
        if (collision.gameObject.CompareTag(&quot;Finish&quot;))
        {
            SceneManager.LoadScene(SceneManager.GetActiveScene().name);
        }
    }
}</code></pre></div>



<h4 class="wp-block-heading"><span id="toc27">▷クリアUI割り当て</span></h4>



<p>クリア用UIテキストをGameManagerの参照に割り当てます。</p>



<figure class="wp-block-image size-full is-resized"><a href="https://d9m.one/wp-content/uploads/2022/07/Pinball_038.png"><img decoding="async" src="https://d9m.one/wp-content/uploads/2022/07/Pinball_038.png" alt="" class="wp-image-636" width="658" height="475" srcset="https://d9m.one/wp-content/uploads/2022/07/Pinball_038.png 877w, https://d9m.one/wp-content/uploads/2022/07/Pinball_038-300x217.png 300w, https://d9m.one/wp-content/uploads/2022/07/Pinball_038-768x554.png 768w" sizes="(max-width: 658px) 100vw, 658px" /></a><figcaption>【クリアUI割り当て】クリア用UIテキストをGameManagerの参照に割り当てる</figcaption></figure>



<ol class="wp-block-list"><li>ヒエラルキーの「Ball」をクリック</li><li>ヒエラルキーの「Canvas＞TextClear」をインスペクターの「Ui Clear」にドラッグ＆ドロップ</li><li>CTRLキーを押しながらSキーを押す</li></ol>



<h4 class="wp-block-heading"><span id="toc28">▷クリア確認</span></h4>



<p>全てのターゲットを取得したら玉が消えてクリアが表示される事を確認します。</p>



<figure class="wp-block-image size-full is-resized"><a href="https://d9m.one/wp-content/uploads/2022/07/Pinball_039.png"><img decoding="async" src="https://d9m.one/wp-content/uploads/2022/07/Pinball_039.png" alt="" class="wp-image-637" width="658" height="475" srcset="https://d9m.one/wp-content/uploads/2022/07/Pinball_039.png 877w, https://d9m.one/wp-content/uploads/2022/07/Pinball_039-300x217.png 300w, https://d9m.one/wp-content/uploads/2022/07/Pinball_039-768x554.png 768w" sizes="(max-width: 658px) 100vw, 658px" /></a><figcaption>【クリア確認】全てのターゲットを取得したら玉が消えてクリアが表示される事を確認</figcaption></figure>



<ol class="wp-block-list"><li>エディタ上中央の「▶」をクリック</li><li>全てのターゲットを取得する</li><li>玉が消え、クリアが表示される事を確認</li><li>エディタ上中央の「▶」をクリック</li></ol>
</div>



<div style="height:16px" aria-hidden="true" class="wp-block-spacer"></div>



<p class="has-text-align-center has-x-large-font-size">完成！</p>



<p>作成手順を書いた記事です。</p>



<p>　　　<a href="https://d9m.one/proc_pinball/">→紹介</a><br>　　　<a href="https://d9m.one/proc_pinball1/">→１／２　オブジェクト作成</a><br>今▷　<a href="https://d9m.one/proc_pinball2/">→２／２　オブジェクト機能</a></p>



<p><a href="https://d9m.one/proc_tandh_full/">完全手順</a><br>※紹介と１～２の手順を１ページにまとめています。<br>　読み込みに時間がかかるかも知れません。</p>
<p>投稿 <a href="https://d9m.one/proc_pinball2/">【基本操作】ピンボール～２／２　オブジェクト機能【アクション】</a> は <a href="https://d9m.one">だくまたゲーム制作ブログ</a> に最初に表示されました。</p>
]]></content:encoded>
					
					<wfw:commentRss>https://d9m.one/proc_pinball2/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>【基本操作】ピンボール～１／２　オブジェクト作成【アクション】</title>
		<link>https://d9m.one/proc_pinball1/</link>
					<comments>https://d9m.one/proc_pinball1/#respond</comments>
		
		<dc:creator><![CDATA[だくまた]]></dc:creator>
		<pubDate>Tue, 05 Jul 2022 12:35:09 +0000</pubDate>
				<category><![CDATA[Unity]]></category>
		<category><![CDATA[基本操作]]></category>
		<category><![CDATA[チュートリアル]]></category>
		<guid isPermaLink="false">https://d9m.one/?p=996</guid>

					<description><![CDATA[<p>●オブジェクト作成 ▷球作成 銀メタリックの球を作成し、(11.125, 4.5, 0)に配置、スケールを(1, 1, 1)とします。 ヒエラルキー左上の「＋」をクリックし、「3Dオブジェクト＞スフィア」をクリック 「B [&#8230;]</p>
<p>投稿 <a href="https://d9m.one/proc_pinball1/">【基本操作】ピンボール～１／２　オブジェクト作成【アクション】</a> は <a href="https://d9m.one">だくまたゲーム制作ブログ</a> に最初に表示されました。</p>
]]></description>
										<content:encoded><![CDATA[
<div style="height:16px" aria-hidden="true" class="wp-block-spacer"></div>



<h3 class="has-background has-medium-font-size wp-block-heading" style="background-color:#e5f7fd"><span id="toc1">●オブジェクト作成</span></h3>



<div style="height:16px" aria-hidden="true" class="wp-block-spacer"></div>



<div class="wp-block-group is-layout-flow wp-block-group-is-layout-flow">
<h4 class="wp-block-heading"><span id="toc2">▷球作成</span></h4>



<p>銀メタリックの球を作成し、(11.125, 4.5, 0)に配置、スケールを(1, 1, 1)とします。</p>



<figure class="wp-block-image size-full is-resized"><a href="https://d9m.one/wp-content/uploads/2022/07/Pinball_000.png"><img decoding="async" src="https://d9m.one/wp-content/uploads/2022/07/Pinball_000.png" alt="" class="wp-image-562" width="658" height="475"/></a><figcaption>【球作成】銀メタリックの球を作成し、(11.125, 4.5, 0)に配置、スケールを(1, 1, 1)とする</figcaption></figure>



<ol class="wp-block-list"><li>ヒエラルキー左上の「＋」をクリックし、「3Dオブジェクト＞スフィア」をクリック</li><li>「Ball」と入力し、ENTERキーを押す</li><li>インスペクターの「Transform＞縦の三点リーダー」をクリックし、リセットをクリック</li><li>インスペクターの「Transform＞位置」を(11.125, 4.5, 0)に設定</li><li>プロジェクト左上の「＋」をクリックし、「マテリアル」をクリック</li><li>「matBall」と入力し、ENTERキーを押す</li><li>インスペクターの「メタリック」を「1」に設定</li><li>インスペクターの「アルベド＞カラーバー」をクリックし、色ダイアログの16進数を「C9CACA」に設定</li><li>色ダイアログの右上にある「×」をクリック</li><li>プロジェクトの「matBall」をヒエラルキーの「Ball」にドラッグ＆ドロップ</li><li>CTRLキーを押しながらSキーを押す</li></ol>



<h4 class="wp-block-heading"><span id="toc3">▷打ち出し器作成</span></h4>



<p>ラベンダー色の円柱を作成し、(11.125, 0, 0)に配置、スケールを(1, 4, 1)とします。</p>



<figure class="wp-block-image size-full is-resized"><a href="https://d9m.one/wp-content/uploads/2022/07/Pinball_001.png"><img decoding="async" src="https://d9m.one/wp-content/uploads/2022/07/Pinball_001.png" alt="" class="wp-image-587" width="658" height="475"/></a><figcaption>【打ち出し器作成】ラベンダー色の円柱を作成し、(11.125, 0, 0)に配置、スケールを(1, 4, 1)とする</figcaption></figure>



<ol class="wp-block-list"><li>ヒエラルキー左上の「＋」をクリックし、「3Dオブジェクト＞シリンダー」をクリック</li><li>「Plunger」と入力し、ENTERキーを押す</li><li>インスペクターの「Transform＞位置」を(11.125, 0, 0)に設定</li><li>インスペクターの「Transform＞スケール」を(1, 4, 1)に設定</li><li>プロジェクト左上の「＋」をクリックし、「マテリアル」をクリック</li><li>「matPlunger」と入力し、ENTERキーを押す</li><li>インスペクターの「アルベド＞カラーバー」をクリックし、色ダイアログの16進数を「CAB8D9」に設定</li><li>色ダイアログの右上にある「×」をクリック</li><li>プロジェクトの「matPlunger」をヒエラルキーの「Plunger」にドラッグ＆ドロップ</li><li>CTRLキーを押しながらSキーを押す</li></ol>



<h4 class="wp-block-heading"><span id="toc4">▷フリッパー作成</span></h4>



<p>フリッパーとして空オブジェクトを作成してプレハブ化し、<br>以下４つのプリミティブを子供として格納します。<br>緑色の円柱１：位置(0, 0, 0)、回転(90, 0, 0)、スケール(1, 0.5, 1)<br>緑色の円柱２：位置(3, -0.25, 0)、回転(90, 0, 0)、スケール(0.5, 0.5, 0.5)<br>緑色の箱１：位置(1.5, -0.25, 0)、回転(0, 0, 0)、スケール(3, 0.5, 1)<br>緑色の箱２：位置(1.5, 0, 0)、回転(0, 0, -9.4)、スケール(3, 0.5, 1)</p>



<figure class="wp-block-image size-full is-resized"><a href="https://d9m.one/wp-content/uploads/2022/07/Pinball_002.png"><img decoding="async" src="https://d9m.one/wp-content/uploads/2022/07/Pinball_002.png" alt="" class="wp-image-564" width="658" height="475"/></a><figcaption>【フリッパー作成】フリッパーとして空オブジェクトを作成してプレハブ化し、<br>以下４つのプリミティブを子供として格納する<br>緑色の円柱１：位置(0, 0, 0)、回転(90, 0, 0)、スケール(1, 0.5, 1)<br>緑色の円柱２：位置(3, -0.25, 0)、回転(90, 0, 0)、スケール(0.5, 0.5, 0.5)<br>緑色の箱１：位置(1.5, -0.25, 0)、回転(0, 0, 0)、スケール(3, 0.5, 1)<br>緑色の箱２：位置(1.5, 0, 0)、回転(0, 0, -9.4)、スケール(3, 0.5, 1)</figcaption></figure>



<ol class="wp-block-list"><li>ヒエラルキー左上の「＋」をクリックし、「空のオブジェクトを作成」をクリック</li><li>「Flipper」と入力し、ENTERキーを押す</li><li>インスペクターの「Transform＞縦の三点リーダー」をクリックし、リセットをクリック</li><li>ヒエラルキーの「Flipper」をプロジェクトの「Assets」にドラッグ＆ドロップ</li><li>プロジェクトの「Assets＞Flipper」をダブルクリック</li><li>ヒエラルキー左上の「＋」をクリックし、「3Dオブジェクト＞シリンダー」をクリック</li><li>インスペクターの「Transform＞位置」を(0, 0, 0)に設定</li><li>インスペクターの「Transform＞回転」を(90, 0, 0)に設定</li><li>インスペクターの「Transform＞スケール」を(1, 0.5, 1)に設定</li><li>ヒエラルキー左上の「＋」をクリックし、「3Dオブジェクト＞シリンダー」をクリック</li><li>インスペクターの「Transform＞位置」を(3, -0.25, 0)に設定</li><li>インスペクターの「Transform＞回転」を(90, 0, 0)に設定</li><li>インスペクターの「Transform＞スケール」を(0.5, 0.5, 0.5)に設定</li><li>ヒエラルキー左上の「＋」をクリックし、「3Dオブジェクト＞キューブ」をクリック</li><li>インスペクターの「Transform＞位置」を(1.5, -0.25, 0)に設定</li><li>インスペクターの「Transform＞スケール」を(3, 0.5, 1)に設定</li><li>ヒエラルキー左上の「＋」をクリックし、「3Dオブジェクト＞キューブ」をクリック</li><li>インスペクターの「Transform＞位置」を(1.5, 0, 0)に設定</li><li>インスペクターの「Transform＞回転」を(0, 0, -9.4)に設定</li><li>インスペクターの「Transform＞スケール」を(3, 0.5, 1)に設定</li><li>プロジェクト左上の「＋」をクリックし、「マテリアル」をクリック</li><li>「matFlipper」と入力し、ENTERキーを押す</li><li>インスペクターの「アルベド＞カラーバー」をクリックし、色ダイアログの16進数を「00FF00」に設定</li><li>色ダイアログの右上にある「×」をクリック</li><li>ヒエラルキーの「Flipper＞Cylinder」をクリック</li><li>SHIFTを押したまま、ヒエラルキーの「Flipper＞Cute (1)」をクリック</li><li>プロジェクトの「matFlipper」をインスペクターの「コンポーネントに追加」にドラッグ＆ドロップ</li><li>ヒエラルキー左上の「＜」をクリック</li><li>CTRLキーを押しながらSキーを押す</li></ol>



<h4 class="wp-block-heading"><span id="toc5">▷ターゲット作成</span></h4>



<p>黄色の箱を作成し、(0, 35, 0)に配置、回転を(0, 45, 0)、スケールを(1, 1, 1)としてプレハブ化します。</p>



<figure class="wp-block-image size-full is-resized"><a href="https://d9m.one/wp-content/uploads/2022/07/Pinball_003.png"><img decoding="async" src="https://d9m.one/wp-content/uploads/2022/07/Pinball_003.png" alt="" class="wp-image-565" width="658" height="475"/></a><figcaption>【ターゲット作成】黄色の箱を作成し、(0, 35, 0)に配置、回転を(0, 45, 0)、スケールを(1, 1, 1)としてプレハブ化する</figcaption></figure>



<ol class="wp-block-list"><li>ヒエラルキー左上の「＋」をクリックし、「3Dオブジェクト＞キューブ」をクリック</li><li>「Target」と入力し、ENTERキーを押す</li><li>インスペクターの「Transform＞位置」を(0, 35, 0)に設定</li><li>インスペクターの「Transform＞回転」を(0, 45, 0)に設定</li><li>インスペクターの「Transform＞スケール」を(1, 1, 1)に設定</li><li>プロジェクト左上の「＋」をクリックし、「マテリアル」をクリック</li><li>「matTarget」と入力し、ENTERキーを押す</li><li>インスペクターの「アルベド＞カラーバー」をクリックし、色ダイアログの16進数を「FFFF00」に設定</li><li>色ダイアログの右上にある「×」をクリック</li><li>プロジェクトの「matTarget」をヒエラルキーの「Target」にドラッグ＆ドロップ</li><li>ヒエラルキーの「Target」をプロジェクトの「Assets」にドラッグ＆ドロップ</li><li>CTRLキーを押しながらSキーを押す</li></ol>



<h4 class="wp-block-heading"><span id="toc6">▷バンパー作成</span></h4>



<p>茶色の円柱を作成し、(0, 27, 0)に配置、回転を(90, 0, 0)、スケールを(3, 0.5, 3)としてプレハブ化します。</p>



<figure class="wp-block-image size-full is-resized"><a href="https://d9m.one/wp-content/uploads/2022/07/Pinball_004.png"><img decoding="async" src="https://d9m.one/wp-content/uploads/2022/07/Pinball_004.png" alt="" class="wp-image-566" width="658" height="475"/></a><figcaption>【バンパー作成】茶色の円柱を作成し、(0, 27, 0)に配置、回転を(90, 0, 0)、スケールを(3, 0.5, 3)としてプレハブ化する</figcaption></figure>



<ol class="wp-block-list"><li>ヒエラルキー左上の「＋」をクリックし、「3Dオブジェクト＞シリンダー」をクリック</li><li>「Bumper」と入力し、ENTERキーを押す</li><li>インスペクターの「Transform＞位置」を(0, 27, 0)に設定</li><li>インスペクターの「Transform＞回転」を(90, 0, 0)に設定</li><li>インスペクターの「Transform＞スケール」を(3, 0.5, 3)に設定</li><li>プロジェクト左上の「＋」をクリックし、「マテリアル」をクリック</li><li>「matBumper」と入力し、ENTERキーを押す</li><li>インスペクターの「アルベド＞カラーバー」をクリックし、色ダイアログの16進数を「800000」に設定</li><li>色ダイアログの右上にある「×」をクリック</li><li>プロジェクトの「matBumper」をヒエラルキーの「Bumper」にドラッグ＆ドロップ</li><li>ヒエラルキーの「Bumper」をプロジェクトの「Assets」にドラッグ＆ドロップ</li><li>CTRLキーを押しながらSキーを押す</li></ol>



<h4 class="wp-block-heading"><span id="toc7">▷ミスエリア作成</span></h4>



<p>赤色の箱を作成し、(0, -6, 0)に配置、スケールを(20, 1, 1)とします。</p>



<figure class="wp-block-image size-full is-resized"><a href="https://d9m.one/wp-content/uploads/2022/07/Pinball_005.png"><img decoding="async" src="https://d9m.one/wp-content/uploads/2022/07/Pinball_005.png" alt="" class="wp-image-567" width="658" height="475"/></a><figcaption>【ミスエリア作成】赤色の箱を作成し、(0, -6, 0)に配置、スケールを(20, 1, 1)とする</figcaption></figure>



<ol class="wp-block-list"><li>ヒエラルキー左上の「＋」をクリックし、「3Dオブジェクト＞キューブ」をクリック</li><li>「WallMiss」と入力し、ENTERキーを押す</li><li>インスペクターの「Transform＞位置」を(0, -6, 0)に設定</li><li>インスペクターの「Transform＞スケール」を(20, 1, 1)に設定</li><li>プロジェクト左上の「＋」をクリックし、「マテリアル」をクリック</li><li>「matWallMiss」と入力し、ENTERキーを押す</li><li>インスペクターの「アルベド＞カラーバー」をクリックし、色ダイアログの16進数を「FF0000」に設定</li><li>色ダイアログの右上にある「×」をクリック</li><li>プロジェクトの「matWallMiss」をヒエラルキーの「WallMiss」にドラッグ＆ドロップ</li><li>CTRLキーを押しながらSキーを押す</li></ol>



<h4 class="wp-block-heading"><span id="toc8">▷シーン確認</span></h4>



<p>シーンカメラを動かし、作成したオブジェクトを確認します。</p>



<figure class="wp-block-image size-full is-resized"><a href="https://d9m.one/wp-content/uploads/2022/07/Pinball_006.png"><img decoding="async" src="https://d9m.one/wp-content/uploads/2022/07/Pinball_006.png" alt="" class="wp-image-571" width="658" height="475"/></a><figcaption>【シーン確認】シーンカメラを動かし、作成したオブジェクトを確認する</figcaption></figure>



<ol class="wp-block-list"><li>マウスホイールを手前に回転する</li><li>マウス右ボタンを押したまま、マウスを上下左右に動かす</li><li>マウス中央ボタンを押したまま、マウスを上下左右に動かす</li><li>上下左右キーを押す</li><li>以上を繰り返し、シーンに配置したオブジェクトを確認する</li></ol>
</div>



<h3 class="has-background has-medium-font-size wp-block-heading" style="background-color:#e5f7fd"><span id="toc9">●オブジェクト配置</span></h3>



<div style="height:16px" aria-hidden="true" class="wp-block-spacer"></div>



<div class="wp-block-group is-layout-flow wp-block-group-is-layout-flow">
<h4 class="wp-block-heading"><span id="toc10">▷カメラ調整</span></h4>



<p>カメラを位置(0, 11, -40)、回転(350, 0, 0)、背景色(202080)とします。</p>



<figure class="wp-block-image size-full is-resized"><a href="https://d9m.one/wp-content/uploads/2022/07/Pinball_007.png"><img decoding="async" src="https://d9m.one/wp-content/uploads/2022/07/Pinball_007.png" alt="" class="wp-image-573" width="658" height="475"/></a><figcaption>【カメラ調整】カメラを位置(0, 11, -40)、回転(350, 0, 0)、背景色(202080)とする</figcaption></figure>



<ol class="wp-block-list"><li>ヒエラルキーの「Main Camera」をクリック</li><li>インスペクターの「Transform＞位置」を(0, 11 -40)に設定</li><li>インスペクターの「Transform＞回転」を(350, 0, 0)に設定</li><li>インスペクターの「Camera＞クリアフラグ」を「ソリッドカラー」に設定</li><li>インスペクターの「Camera＞背景」のカラーバーをクリックし、色ダイアログの16進数を「202080」に設定</li><li>色ダイアログの右上にある「×」をクリック</li><li>CTRLキーを押しながらSキーを押す</li><li>ゲームビューの「FreeAspect」をクリック</li><li>「9:16 Aspect」をクリック（無い場合は以下を操作）</li><li>左下の「＋」をクリック</li><li>ドロップダウン「タイプ」をクリックし、「アスペクト比」をクリック</li><li>幅＆高さの「X」に(9)、「Y」に(16)を入力</li><li>「OK」をクリック</li></ol>



<h4 class="wp-block-heading"><span id="toc11">▷左壁作成</span></h4>



<p>緑色の箱を作成し、(-10, 19, 0)に配置、スケールを(1, 43, 1)とします。</p>



<figure class="wp-block-image size-full is-resized"><a href="https://d9m.one/wp-content/uploads/2022/07/Pinball_008.png"><img decoding="async" src="https://d9m.one/wp-content/uploads/2022/07/Pinball_008.png" alt="" class="wp-image-574" width="658" height="475"/></a><figcaption>【左壁作成】緑色の箱を作成し、(-10, 19, 0)に配置、スケールを(1, 43, 1)とする</figcaption></figure>



<ol class="wp-block-list"><li>ヒエラルキー左上の「＋」をクリックし、「3Dオブジェクト＞キューブ」をクリック</li><li>「WallLeft」と入力し、ENTERキーを押す</li><li>インスペクターの「Transform＞縦の三点リーダー」をクリックし、リセットをクリック</li><li>インスペクターの「Transform＞位置」を(-10, 19, 0)に設定</li><li>インスペクターの「Transform＞スケール」を(1, 43, 1)に設定</li><li>プロジェクト左上の「＋」をクリックし、「マテリアル」をクリック</li><li>「matWall」と入力し、ENTERキーを押す</li><li>インスペクターの「アルベド＞カラーバー」をクリックし、色ダイアログの16進数を「008000」に設定</li><li>色ダイアログの右上にある「×」をクリック</li><li>プロジェクトの「matWall」をヒエラルキーの「WallLeft」にドラッグ＆ドロップ</li><li>CTRLキーを押しながらSキーを押す</li></ol>



<h4 class="wp-block-heading"><span id="toc12">▷右壁作成</span></h4>



<p>緑色の箱を２つ作成し、以下のように配置します。<br>箱１：位置(10, 17, 0)、スケールを(1, 39, 1)<br>箱２：位置(12.25, 20, 0)、スケールを(1, 41, 1)</p>



<figure class="wp-block-image size-full is-resized"><a href="https://d9m.one/wp-content/uploads/2022/07/Pinball_009.png"><img decoding="async" src="https://d9m.one/wp-content/uploads/2022/07/Pinball_009.png" alt="" class="wp-image-575" width="658" height="475"/></a><figcaption>【右壁作成】緑色の箱を２つ作成し、以下のように配置<br>箱１：位置(10, 17, 0)、スケールを(1, 39, 1)<br>箱２：位置(12.25, 20, 0)、スケールを(1, 41, 1)</figcaption></figure>



<ol class="wp-block-list"><li>ヒエラルキーの「WallLeft」をクリックし、CTRLを押しながらDキーを押す</li><li>F2キーを押して「WallRight1」と入力し、ENTERキーを押す</li><li>インスペクターの「Transform＞位置」を(10, 17, 0)に設定</li><li>インスペクターの「Transform＞スケール」を(1, 39, 1)に設定</li><li>ヒエラルキーの「WallRight1」をクリックし、CTRLを押しながらDキーを押す</li><li>F2キーを押して「WallRight2」と入力し、ENTERキーを押す</li><li>インスペクターの「Transform＞位置」を(12.25, 20, 0)に設定</li><li>インスペクターの「Transform＞スケール」を(1, 41, 1)に設定</li><li>CTRLキーを押しながらSキーを押す</li></ol>



<h4 class="wp-block-heading"><span id="toc13">▷上壁作成</span></h4>



<p>緑色の箱を２つ作成し、以下のように配置します。<br>箱１：位置(-5, 42, 0)、回転(0, 0, 290)、スケールを(1, 11, 1)<br>箱２：位置(6, 41.65, 0)、回転(0, 0, 70)、スケールを(1, 13, 1)</p>



<figure class="wp-block-image size-full is-resized"><a href="https://d9m.one/wp-content/uploads/2022/07/Pinball_010.png"><img decoding="async" src="https://d9m.one/wp-content/uploads/2022/07/Pinball_010.png" alt="" class="wp-image-576" width="658" height="475"/></a><figcaption>【上壁作成】緑色の箱を２つ作成し、以下のように配置<br>箱１：位置(-5, 42, 0)、回転(0, 0, 290)、スケールを(1, 11, 1)<br>箱２：位置(6, 41.65, 0)、回転(0, 0, 70)、スケールを(1, 13, 1)</figcaption></figure>



<ol class="wp-block-list"><li>ヒエラルキーの「WallLeft」をクリックし、CTRLを押しながらDキーを押す</li><li>F2キーを押して「WallTopL」と入力し、ENTERキーを押す</li><li>インスペクターの「Transform＞位置」を(-5, 42, 0)に設定</li><li>インスペクターの「Transform＞回転」を(0, 0, 290)に設定</li><li>インスペクターの「Transform＞スケール」を(1, 11, 1)に設定</li><li>ヒエラルキーの「WallTopL」をクリックし、CTRLを押しながらDキーを押す</li><li>F2キーを押して「WallTopR」と入力し、ENTERキーを押す</li><li>インスペクターの「Transform＞位置」を(6, 41.65, 0)に設定</li><li>インスペクターの「Transform＞回転」を(0, 0, 70)に設定</li><li>インスペクターの「Transform＞スケール」を(1, 13, 1)に設定</li><li>CTRLキーを押しながらSキーを押す</li></ol>



<h4 class="wp-block-heading"><span id="toc14">▷フリッパー左側の壁作成</span></h4>



<p>緑色の箱を２つ作成し、以下のように配置します。<br>箱１：位置(-7.75, 3.5, 0)、回転(0, 0, 0)、スケールを(1, 5, 1)<br>箱２：位置(-6, 0.7, 0)、回転(0, 0, 250)、スケールを(1, 4, 1)</p>



<figure class="wp-block-image size-full is-resized"><a href="https://d9m.one/wp-content/uploads/2022/07/Pinball_011.png"><img decoding="async" src="https://d9m.one/wp-content/uploads/2022/07/Pinball_011.png" alt="" class="wp-image-577" width="658" height="475"/></a><figcaption>【フリッパー左側の壁作成】緑色の箱を２つ作成し、以下のように配置<br>箱１：位置(-7.75, 3.5, 0)、回転(0, 0, 0)、スケールを(1, 5, 1)<br>箱２：位置(-6, 0.7, 0)、回転(0, 0, 250)、スケールを(1, 4, 1)</figcaption></figure>



<ol class="wp-block-list"><li>ヒエラルキーの「WallLeft」をクリックし、CTRLを押しながらDキーを押す</li><li>F2キーを押して「WallFlipL1」と入力し、ENTERキーを押す</li><li>インスペクターの「Transform＞位置」を(-7.75, 3.5, 0)に設定</li><li>インスペクターの「Transform＞回転」を(0, 0, 0)に設定</li><li>インスペクターの「Transform＞スケール」を(1, 5, 1)に設定</li><li>ヒエラルキーの「WallFlipL1」をクリックし、CTRLを押しながらDキーを押す</li><li>F2キーを押して「WallFlipL2」と入力し、ENTERキーを押す</li><li>インスペクターの「Transform＞位置」を(-6, 0.7, 0)に設定</li><li>インスペクターの「Transform＞回転」を(0, 0, 250)に設定</li><li>インスペクターの「Transform＞スケール」を(1, 4, 1)に設定</li><li>CTRLキーを押しながらSキーを押す</li></ol>



<h4 class="wp-block-heading"><span id="toc15">▷フリッパー右側の壁作成</span></h4>



<p>緑色の箱を２つ作成し、以下のように配置します。<br>箱１：位置(-7.75, 3.5, 0)、回転(0, 0, 0)、スケールを(1, 5, 1)<br>箱２：位置(-6, 0.7, 0)、回転(0, 0, 290)、スケールを(1, 4, 1)</p>



<figure class="wp-block-image size-full is-resized"><a href="https://d9m.one/wp-content/uploads/2022/07/Pinball_012.png"><img decoding="async" src="https://d9m.one/wp-content/uploads/2022/07/Pinball_012.png" alt="" class="wp-image-580" width="658" height="475"/></a><figcaption>【フリッパー右側の壁作成】緑色の箱を２つ作成し、以下のように配置<br>箱１：位置(-7.75, 3.5, 0)、回転(0, 0, 0)、スケールを(1, 5, 1)<br>箱２：位置(-6, 0.7, 0)、回転(0, 0, 290)、スケールを(1, 4, 1)</figcaption></figure>



<ol class="wp-block-list"><li>ヒエラルキーの「WallFlipL1」をクリック</li><li>CTRLを押しながらヒエラルキーの「WallFlipL2」をクリック</li><li>CTRLを押しながらDキーを押す</li><li>ヒエラルキーの「WallFlipL1 (1)」をクリック</li><li>F2キーを押して「WallFlipR1」と入力し、ENTERキーを押す</li><li>インスペクターの「Transform＞位置＞X」を(7.75)に設定</li><li>ヒエラルキーの「WallFlipL2 (1)」をクリック</li><li>F2キーを押して「WallFlipR2」と入力し、ENTERキーを押す</li><li>インスペクターの「Transform＞位置＞X」を(6)に設定</li><li>インスペクターの「Transform＞回転＞Z」を(290)に設定</li><li>CTRLキーを押しながらSキーを押す</li></ol>



<h4 class="wp-block-heading"><span id="toc16">▷下壁作成</span></h4>



<p>緑色の箱を２つ作成し、以下のように配置します。<br>箱１：位置(-5.5, -2, 0)、回転(0, 0, 70)、スケールを(1, 10, 1)<br>箱２：位置(5.5, -2, 0)、回転(0, 0, 290)、スケールを(1, 10, 1)</p>



<figure class="wp-block-image size-full is-resized"><a href="https://d9m.one/wp-content/uploads/2022/07/Pinball_013.png"><img decoding="async" src="https://d9m.one/wp-content/uploads/2022/07/Pinball_013.png" alt="" class="wp-image-581" width="658" height="475"/></a><figcaption>【下壁作成】緑色の箱を２つ作成し、以下のように配置<br>箱１：位置(-5.5, -2, 0)、回転(0, 0, 70)、スケールを(1, 10, 1)<br>箱２：位置(5.5, -2, 0)、回転(0, 0, 290)、スケールを(1, 10, 1)</figcaption></figure>



<ol class="wp-block-list"><li>ヒエラルキーの「WallLeft」をクリックし、CTRLを押しながらDキーを押す</li><li>F2キーを押して「WallBottomL」と入力し、ENTERキーを押す</li><li>インスペクターの「Transform＞位置」を(-5.5, -2, 0)に設定</li><li>インスペクターの「Transform＞回転」を(0, 0, 70)に設定</li><li>インスペクターの「Transform＞スケール」を(1, 10, 1)に設定</li><li>ヒエラルキーの「WallBottomL」をクリックし、CTRLを押しながらDキーを押す</li><li>F2キーを押して「WallBottomR」と入力し、ENTERキーを押す</li><li>インスペクターの「Transform＞位置＞X」を(5.5)に設定</li><li>インスペクターの「Transform＞回転＞Z」を(290)に設定</li><li>CTRLキーを押しながらSキーを押す</li></ol>



<h4 class="wp-block-heading"><span id="toc17">▷フリッパー配置</span></h4>



<p>フリッパーを複製し、以下のように配置します。<br>フリッパー１：位置(-3.7, 0, 0)、回転(0, 0, -18)<br>フリッパー２：位置(3.7, 0, 0)、回転(0, 180, -18)</p>



<figure class="wp-block-image size-full is-resized"><a href="https://d9m.one/wp-content/uploads/2022/07/Pinball_014.png"><img decoding="async" src="https://d9m.one/wp-content/uploads/2022/07/Pinball_014.png" alt="" class="wp-image-582" width="658" height="475"/></a><figcaption>【フリッパー配置】フリッパーを複製し、以下のように配置<br>フリッパー１：位置(-3.7, 0, 0)、回転(0, 0, -18)<br>フリッパー２：位置(3.7, 0, 0)、回転(0, 180, -18)</figcaption></figure>



<ol class="wp-block-list"><li>ヒエラルキーの「Flipper」をクリック</li><li>F2キーを押して「FlipperL」と入力し、ENTERキーを押す</li><li>インスペクターの「Transform＞位置」を(-3.7, 0, 0)に設定</li><li>インスペクターの「Transform＞回転」を(0, 0, -18)に設定</li><li>ヒエラルキーの「FlipperL」をクリック</li><li>CTRLを押しながらDキーを押す</li><li>F2キーを押して「FlipperR」と入力し、ENTERキーを押す</li><li>インスペクターの「Transform＞位置＞X」を(3.7)に設定</li><li>インスペクターの「Transform＞回転＞Y」を(180)に設定</li><li>CTRLキーを押しながらSキーを押す</li></ol>



<h4 class="wp-block-heading"><span id="toc18">▷ターゲット配置</span></h4>



<p>ターゲットを複製し、以下のように配置します。<br>ターゲット１：位置(0, 35, 0)<br>ターゲット２：位置(-6, 30, 0)<br>ターゲット３：位置(6, 30, 0)<br>ターゲット４：位置(-4, 20, 0)<br>ターゲット５：位置(4, 20, 0)</p>



<figure class="wp-block-image size-full is-resized"><a href="https://d9m.one/wp-content/uploads/2022/07/Pinball_015.png"><img decoding="async" src="https://d9m.one/wp-content/uploads/2022/07/Pinball_015.png" alt="" class="wp-image-583" width="658" height="475"/></a><figcaption>【ターゲット配置】ターゲットを複製し、以下のように配置<br>ターゲット１：位置(0, 35, 0)<br>ターゲット２：位置(-6, 30, 0)<br>ターゲット３：位置(6, 30, 0)<br>ターゲット４：位置(-4, 20, 0)<br>ターゲット５：位置(4, 20, 0)</figcaption></figure>



<ol class="wp-block-list"><li>ヒエラルキーの「Target」をクリック</li><li>CTRLを押しながらDキーを押す</li><li>インスペクターの「Transform＞位置」を(-6, 30, 0)に設定</li><li>ヒエラルキーの「Target (1)」をクリック</li><li>CTRLを押しながらDキーを押す</li><li>インスペクターの「Transform＞位置＞X」を(6)に設定</li><li>ヒエラルキーの「Target (2)」をクリック</li><li>CTRLを押しながらDキーを押す</li><li>インスペクターの「Transform＞位置」を(-4, 20, 0)に設定</li><li>ヒエラルキーの「Target (3)」をクリック</li><li>CTRLを押しながらDキーを押す</li><li>インスペクターの「Transform＞位置＞X」を(4)に設定</li><li>CTRLキーを押しながらSキーを押す</li></ol>



<h4 class="wp-block-heading"><span id="toc19">▷バンパー配置</span></h4>



<p>フリッパーを複製し、以下のように配置します。<br>バンパー１：位置(0, 27, 0)<br>バンパー２：位置(-5, 10, 0)<br>バンパー３：位置(5, 10, 0)</p>



<figure class="wp-block-image size-full is-resized"><a href="https://d9m.one/wp-content/uploads/2022/07/Pinball_016.png"><img decoding="async" src="https://d9m.one/wp-content/uploads/2022/07/Pinball_016.png" alt="" class="wp-image-608" width="658" height="475" srcset="https://d9m.one/wp-content/uploads/2022/07/Pinball_016.png 877w, https://d9m.one/wp-content/uploads/2022/07/Pinball_016-300x217.png 300w, https://d9m.one/wp-content/uploads/2022/07/Pinball_016-768x554.png 768w" sizes="(max-width: 658px) 100vw, 658px" /></a><figcaption>【バンパー配置】フリッパーを複製し、以下のように配置<br>バンパー１：位置(0, 27, 0)<br>バンパー２：位置(-5, 10, 0)<br>バンパー３：位置(5, 10, 0)</figcaption></figure>



<ol class="wp-block-list"><li>ヒエラルキーの「Bumper」をクリック</li><li>CTRLを押しながらDキーを押す</li><li>インスペクターの「Transform＞位置」を(-5, 10, 0)に設定</li><li>ヒエラルキーの「Bumper (1)」をクリック</li><li>CTRLを押しながらDキーを押す</li><li>インスペクターの「Transform＞位置＞X」を(5)に設定</li><li>CTRLキーを押しながらSキーを押す</li></ol>
</div>



<h3 class="has-background has-medium-font-size wp-block-heading" style="background-color:#e5f7fd"><span id="toc20">●オブジェクト整理</span></h3>



<div style="height:16px" aria-hidden="true" class="wp-block-spacer"></div>



<div class="wp-block-group is-layout-flow wp-block-group-is-layout-flow">
<h4 class="wp-block-heading"><span id="toc21">▷壁整理</span></h4>



<p>空オブジェクトを作成し、「全ての壁」を格納します。</p>



<figure class="wp-block-image size-full is-resized"><a href="https://d9m.one/wp-content/uploads/2022/07/Pinball_017.png"><img decoding="async" src="https://d9m.one/wp-content/uploads/2022/07/Pinball_017.png" alt="" class="wp-image-584" width="658" height="475"/></a><figcaption>【壁整理】空オブジェクトを作成し、「全ての壁」を格納</figcaption></figure>



<ol class="wp-block-list"><li>ヒエラルキー左上「＋」をクリックし、「空のオブジェクトを作成」をクリック</li><li>「Walls」と入力し、ENTERキーを押す</li><li>インスペクターの「Transform＞縦の三点リーダー」をクリックし、リセットをクリック</li><li>ヒエラルキーの「WallLeft」をクリック</li><li>CTRLを押したまま、ヒエラルキーの「WallRight1」をクリック</li><li>CTRLを押したまま、ヒエラルキーの「WallRight2」をクリック</li><li>CTRLを押したまま、ヒエラルキーの「WallTopL」をクリック</li><li>CTRLを押したまま、ヒエラルキーの「WallTopR」をクリック</li><li>CTRLを押したまま、ヒエラルキーの「WallFlipL1」をクリック</li><li>CTRLを押したまま、ヒエラルキーの「WallFlipL2」をクリック</li><li>CTRLを押したまま、ヒエラルキーの「WallFlipR1」をクリック</li><li>CTRLを押したまま、ヒエラルキーの「WallFlipR2」をクリック</li><li>CTRLを押したまま、ヒエラルキーの「WallBottomL」をクリック</li><li>CTRLを押したまま、ヒエラルキーの「WallBottomR」をクリック</li><li>ヒエラルキーの選択ゲームオブジェクトを「Walls」にドラッグ＆ドロップ</li><li>ヒエラルキーの「Walls」左にある三角形をクリック</li><li>CTRLキーを押しながらSキーを押す</li></ol>



<h4 class="wp-block-heading"><span id="toc22">▷ターゲット整理</span></h4>



<p>空オブジェクトを作成し、「全ターゲット」を格納します。</p>



<figure class="wp-block-image size-full is-resized"><a href="https://d9m.one/wp-content/uploads/2022/07/Pinball_018.png"><img decoding="async" src="https://d9m.one/wp-content/uploads/2022/07/Pinball_018.png" alt="" class="wp-image-585" width="658" height="475"/></a><figcaption>【ターゲット整理】空オブジェクトを作成し、「全ターゲット」を格納</figcaption></figure>



<ol class="wp-block-list"><li>ヒエラルキー左上「＋」をクリックし、「空のオブジェクトを作成」をクリック</li><li>「Targets」と入力し、ENTERキーを押す</li><li>インスペクターの「Transform＞縦の三点リーダー」をクリックし、リセットをクリック</li><li>ヒエラルキーの「Target」をクリック</li><li>CTRLを押したまま、ヒエラルキーの「Target (1)」をクリック</li><li>CTRLを押したまま、ヒエラルキーの「Target (2)」をクリック</li><li>CTRLを押したまま、ヒエラルキーの「Target (3)」をクリック</li><li>CTRLを押したまま、ヒエラルキーの「Target (4)」をクリック</li><li>ヒエラルキーの選択ゲームオブジェクトを「Targets」にドラッグ＆ドロップ</li><li>ヒエラルキーの「Targets」左にある三角形をクリック</li><li>CTRLキーを押しながらSキーを押す</li></ol>



<h4 class="wp-block-heading"><span id="toc23">▷バンパー整理</span></h4>



<p>空オブジェクトを作成し、「全バンパー」を格納します。</p>



<figure class="wp-block-image size-full is-resized"><a href="https://d9m.one/wp-content/uploads/2022/07/Pinball_019.png"><img decoding="async" src="https://d9m.one/wp-content/uploads/2022/07/Pinball_019.png" alt="" class="wp-image-586" width="658" height="475"/></a><figcaption>【バンパー整理】空オブジェクトを作成し、「全バンパー」を格納</figcaption></figure>



<ol class="wp-block-list"><li>ヒエラルキー左上「＋」をクリックし、「空のオブジェクトを作成」をクリック</li><li>「Bumpers」と入力し、ENTERキーを押す</li><li>インスペクターの「Transform＞縦の三点リーダー」をクリックし、リセットをクリック</li><li>ヒエラルキーの「Bumper」をクリック</li><li>CTRLを押したまま、ヒエラルキーの「Bumper(1)」をクリック</li><li>CTRLを押したまま、ヒエラルキーの「Bumper(2)」をクリック</li><li>ヒエラルキーの選択ゲームオブジェクトを「Bumpers」にドラッグ＆ドロップ</li><li>ヒエラルキーの「Bumpers」左にある三角形をクリック</li><li>CTRLキーを押しながらSキーを押す</li></ol>



<h4 class="wp-block-heading"><span id="toc24">▷プロジェクト整理</span></h4>



<p>マテリアル用、プレハブ用の格納フォルダを作成して移動します。</p>



<figure class="wp-block-image size-full is-resized"><a href="https://d9m.one/wp-content/uploads/2022/07/Pinball_020.png"><img decoding="async" src="https://d9m.one/wp-content/uploads/2022/07/Pinball_020.png" alt="" class="wp-image-613" width="658" height="475" srcset="https://d9m.one/wp-content/uploads/2022/07/Pinball_020.png 877w, https://d9m.one/wp-content/uploads/2022/07/Pinball_020-300x217.png 300w, https://d9m.one/wp-content/uploads/2022/07/Pinball_020-768x554.png 768w" sizes="(max-width: 658px) 100vw, 658px" /></a><figcaption>【プロジェクト整理】マテリアル用、プレハブ用の格納フォルダを作成して移動</figcaption></figure>



<ol class="wp-block-list"><li>プロジェクト左上の「＋」をクリックし、「フォルダー」をクリック</li><li>「Materials」と入力し、ENTERキーを押す</li><li>プロジェクトの「matBall」をクリック</li><li>CTRLを押したまま「matBumper」をクリック</li><li>CTRLを押したまま「matFlipper」をクリック</li><li>CTRLを押したまま「matPlunger」をクリック</li><li>CTRLを押したまま「matTarget」をクリック</li><li>CTRLを押したまま「matWall」をクリック</li><li>CTRLを押したまま「matWallMiss」をクリック</li><li>プロジェクトで選択中のアセットを「Assets＞Materials」にドラッグ＆ドロップ</li><li>プロジェクトの「Assets」をクリック</li><li>プロジェクト左上の「＋」をクリックし、「フォルダー」をクリック</li><li>「Prefabs」と入力し、ENTERキーを押す</li><li>プロジェクトの「Bumperr」を「Assets＞Prefabs」にドラッグ＆ドロップ</li><li>プロジェクトの「Flipper」を「Assets＞Prefabs」にドラッグ＆ドロップ</li><li>プロジェクトの「Target」を「Assets＞Prefabs」にドラッグ＆ドロップ</li></ol>
</div>



<p>作成手順を書いた記事です。</p>



<p>　　　<a href="https://d9m.one/proc_pinball/">→紹介</a><br>今▷　<a href="https://d9m.one/proc_pinball1/">→１／２　オブジェクト作成</a><br>次▷　<a href="https://d9m.one/proc_pinball2/">→２／２　オブジェクト機能</a></p>



<p><a href="https://d9m.one/proc_pinball_full/">完全手順</a><br>※紹介と１～２の手順を１ページにまとめています。<br>　読み込みに時間がかかるかも知れません。</p>



<div style="height:16px" aria-hidden="true" class="wp-block-spacer"></div>
<p>投稿 <a href="https://d9m.one/proc_pinball1/">【基本操作】ピンボール～１／２　オブジェクト作成【アクション】</a> は <a href="https://d9m.one">だくまたゲーム制作ブログ</a> に最初に表示されました。</p>
]]></content:encoded>
					
					<wfw:commentRss>https://d9m.one/proc_pinball1/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>【基本操作】ピンボール～紹介【アクション】</title>
		<link>https://d9m.one/proc_pinball/</link>
					<comments>https://d9m.one/proc_pinball/#respond</comments>
		
		<dc:creator><![CDATA[だくまた]]></dc:creator>
		<pubDate>Tue, 05 Jul 2022 12:34:44 +0000</pubDate>
				<category><![CDATA[Unity]]></category>
		<category><![CDATA[基本操作]]></category>
		<category><![CDATA[チュートリアル]]></category>
		<guid isPermaLink="false">https://d9m.one/?p=991</guid>

					<description><![CDATA[<p>ピンボール完成までの「操作概要と操作手順」を書いた記事です。 Unity3Dの基本操作を頭と体で習得できます。 スペースキーで球を発射し、左クリックで左のフリッパー、右クリックで右のフリッパーを動かします。 黄色いターゲ [&#8230;]</p>
<p>投稿 <a href="https://d9m.one/proc_pinball/">【基本操作】ピンボール～紹介【アクション】</a> は <a href="https://d9m.one">だくまたゲーム制作ブログ</a> に最初に表示されました。</p>
]]></description>
										<content:encoded><![CDATA[
<pre class="wp-block-preformatted" style="font-size:16px">ピンボール完成までの「操作概要と操作手順」を書いた記事です。
Unity3Dの基本操作を頭と体で習得できます。

スペースキーで球を発射し、左クリックで左のフリッパー、右クリックで右のフリッパーを動かします。

黄色いターゲットを全て集めるとクリア、画面下に球を落とすとミスとなります。

対象：初心者、Unityに初めて触る方
使用バージョン：Unity 2021.3
時間：2時間</pre>



<iframe loading="lazy" src="/game/pinball/index.html" width="450" height="860" scrolling="no" frameborder="0"></iframe>



<p>作成手順を書いた記事です。</p>



<p>今▷　<a href="https://d9m.one/proc_pinball/" type="URL" id="https://d9m.one/proc_pinball">→紹介</a><br>次▷　<a href="https://d9m.one/proc_pinball1/" type="URL" id="https://d9m.one/proc_pinball1">→１／２　オブジェクト作成</a><br>　　　<a href="https://d9m.one/proc_pinball2/" type="URL" id="https://d9m.one/proc_pinball2">→２／２　オブジェクト機能</a></p>



<p><a href="https://d9m.one/proc_pinball_full/" type="URL" id="https://d9m.one/proc_pinball_full">完全手順</a><br>※紹介と１～２の手順を１ページにまとめています。<br>　読み込みに時間がかかるかも知れません。</p>
<p>投稿 <a href="https://d9m.one/proc_pinball/">【基本操作】ピンボール～紹介【アクション】</a> は <a href="https://d9m.one">だくまたゲーム制作ブログ</a> に最初に表示されました。</p>
]]></content:encoded>
					
					<wfw:commentRss>https://d9m.one/proc_pinball/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>【基本操作】ピンボール～完全手順【アクション】</title>
		<link>https://d9m.one/proc_pinball_full/</link>
					<comments>https://d9m.one/proc_pinball_full/#respond</comments>
		
		<dc:creator><![CDATA[だくまた]]></dc:creator>
		<pubDate>Tue, 05 Jul 2022 12:33:16 +0000</pubDate>
				<category><![CDATA[Unity]]></category>
		<category><![CDATA[基本操作]]></category>
		<category><![CDATA[チュートリアル]]></category>
		<guid isPermaLink="false">https://d9m.wp.xdomain.jp/?p=193</guid>

					<description><![CDATA[<p>ピンボール完成までの「操作概要と操作手順」を書いた記事です。 Unity3Dの基本操作を頭と体で習得できます。 スペースキーで球を発射し、左クリックで左のフリッパー、右クリックで右のフリッパーを動かします。 黄色いターゲ [&#8230;]</p>
<p>投稿 <a href="https://d9m.one/proc_pinball_full/">【基本操作】ピンボール～完全手順【アクション】</a> は <a href="https://d9m.one">だくまたゲーム制作ブログ</a> に最初に表示されました。</p>
]]></description>
										<content:encoded><![CDATA[
<pre class="wp-block-preformatted" style="font-size:16px">ピンボール完成までの「操作概要と操作手順」を書いた記事です。
Unity3Dの基本操作を頭と体で習得できます。

スペースキーで球を発射し、左クリックで左のフリッパー、右クリックで右のフリッパーを動かします。

黄色いターゲットを全て集めるとクリア、画面下に球を落とすとミスとなります。

対象：初心者、Unityに初めて触る方
使用バージョン：Unity 2021.3
時間：2時間</pre>



<iframe loading="lazy" src="/game/pinball/index.html" width="450" height="860" scrolling="no" frameborder="0"></iframe>




  <div id="toc" class="toc tnt-number toc-center tnt-number border-element"><input type="checkbox" class="toc-checkbox" id="toc-checkbox-18" checked><label class="toc-title" for="toc-checkbox-18">目次</label>
    <div class="toc-content">
    <ol class="toc-list open"><li><a href="#toc1" tabindex="0">■オブジェクト作成</a><ol><li><a href="#toc2" tabindex="0">●オブジェクト作成</a><ol><li><a href="#toc3" tabindex="0">▷球作成</a></li><li><a href="#toc4" tabindex="0">▷打ち出し器作成</a></li><li><a href="#toc5" tabindex="0">▷フリッパー作成</a></li><li><a href="#toc6" tabindex="0">▷ターゲット作成</a></li><li><a href="#toc7" tabindex="0">▷バンパー作成</a></li><li><a href="#toc8" tabindex="0">▷ミスエリア作成</a></li><li><a href="#toc9" tabindex="0">▷シーン確認</a></li></ol></li><li><a href="#toc10" tabindex="0">●オブジェクト配置</a><ol><li><a href="#toc11" tabindex="0">▷カメラ調整</a></li><li><a href="#toc12" tabindex="0">▷左壁作成</a></li><li><a href="#toc13" tabindex="0">▷右壁作成</a></li><li><a href="#toc14" tabindex="0">▷上壁作成</a></li><li><a href="#toc15" tabindex="0">▷フリッパー左側の壁作成</a></li><li><a href="#toc16" tabindex="0">▷フリッパー右側の壁作成</a></li><li><a href="#toc17" tabindex="0">▷下壁作成</a></li><li><a href="#toc18" tabindex="0">▷フリッパー配置</a></li><li><a href="#toc19" tabindex="0">▷ターゲット配置</a></li><li><a href="#toc20" tabindex="0">▷バンパー配置</a></li></ol></li><li><a href="#toc21" tabindex="0">●オブジェクト整理</a><ol><li><a href="#toc22" tabindex="0">▷壁整理</a></li><li><a href="#toc23" tabindex="0">▷ターゲット整理</a></li><li><a href="#toc24" tabindex="0">▷バンパー整理</a></li><li><a href="#toc25" tabindex="0">▷プロジェクト整理</a></li></ol></li></ol></li><li><a href="#toc26" tabindex="0">■オブジェクト機能</a><ol><li><a href="#toc27" tabindex="0">●プレイヤー制御</a><ol><li><a href="#toc28" tabindex="0">▷スクリプト整理</a></li><li><a href="#toc29" tabindex="0">▷玉物理設定</a></li><li><a href="#toc30" tabindex="0">▷打ち出し器物理設定</a></li><li><a href="#toc31" tabindex="0">▷制御スクリプト作成</a></li><li><a href="#toc32" tabindex="0">▷打ち出し器制御</a></li><li><a href="#toc33" tabindex="0">▷打ち出し器割り当て</a></li><li><a href="#toc34" tabindex="0">▷打ち出し器制御確認</a></li><li><a href="#toc35" tabindex="0">▷フリッパー物理設定</a></li><li><a href="#toc36" tabindex="0">▷フリッパー制御</a></li><li><a href="#toc37" tabindex="0">▷フリッパー割り当て</a></li><li><a href="#toc38" tabindex="0">▷フリッパー制御確認</a></li></ol></li><li><a href="#toc39" tabindex="0">●オブジェクト制御</a><ol><li><a href="#toc40" tabindex="0">▷ターゲット設定</a></li><li><a href="#toc41" tabindex="0">▷ターゲット制御</a></li><li><a href="#toc42" tabindex="0">▷ターゲット制御確認</a></li><li><a href="#toc43" tabindex="0">▷バンパー物理設定</a></li><li><a href="#toc44" tabindex="0">▷バンパー認識</a></li><li><a href="#toc45" tabindex="0">▷バンパー制御</a></li><li><a href="#toc46" tabindex="0">▷バンパー制御確認</a></li></ol></li><li><a href="#toc47" tabindex="0">●ゲーム制御</a><ol><li><a href="#toc48" tabindex="0">▷ミスエリア認識</a></li><li><a href="#toc49" tabindex="0">▷リスタート制御</a></li><li><a href="#toc50" tabindex="0">▷リスタート確認</a></li><li><a href="#toc51" tabindex="0">▷クリアUI作成</a></li><li><a href="#toc52" tabindex="0">▷クリア制御</a></li><li><a href="#toc53" tabindex="0">▷クリアUI割り当て</a></li><li><a href="#toc54" tabindex="0">▷クリア確認</a></li></ol></li></ol></li></ol>
    </div>
  </div>

<h2 class="has-text-align-left has-background has-large-font-size wp-block-heading" style="background-color:#f1e0f8;font-style:normal;font-weight:700"><span id="toc1">■オブジェクト作成</span></h2>



<div style="height:16px" aria-hidden="true" class="wp-block-spacer"></div>



<h3 class="has-background has-medium-font-size wp-block-heading" style="background-color:#e5f7fd"><span id="toc2">●オブジェクト作成</span></h3>



<div style="height:16px" aria-hidden="true" class="wp-block-spacer"></div>



<h4 class="wp-block-heading"><span id="toc3">▷球作成</span></h4>



<p>銀メタリックの球を作成し、(11.125, 4.5, 0)に配置、スケールを(1, 1, 1)とします。</p>



<figure class="wp-block-image size-full is-resized"><a href="https://d9m.one/wp-content/uploads/2022/07/Pinball_000.png"><img decoding="async" src="https://d9m.one/wp-content/uploads/2022/07/Pinball_000.png" alt="" class="wp-image-562" width="658" height="475"/></a><figcaption>【球作成】銀メタリックの球を作成し、(11.125, 4.5, 0)に配置、スケールを(1, 1, 1)とする</figcaption></figure>



<ol class="wp-block-list"><li>ヒエラルキー左上の「＋」をクリックし、「3Dオブジェクト＞スフィア」をクリック</li><li>「Ball」と入力し、ENTERキーを押す</li><li>インスペクターの「Transform＞縦の三点リーダー」をクリックし、リセットをクリック</li><li>インスペクターの「Transform＞位置」を(11.125, 4.5, 0)に設定</li><li>プロジェクト左上の「＋」をクリックし、「マテリアル」をクリック</li><li>「matBall」と入力し、ENTERキーを押す</li><li>インスペクターの「メタリック」を「1」に設定</li><li>インスペクターの「アルベド＞カラーバー」をクリックし、色ダイアログの16進数を「C9CACA」に設定</li><li>色ダイアログの右上にある「×」をクリック</li><li>プロジェクトの「matBall」をヒエラルキーの「Ball」にドラッグ＆ドロップ</li><li>CTRLキーを押しながらSキーを押す</li></ol>



<h4 class="wp-block-heading"><span id="toc4">▷打ち出し器作成</span></h4>



<p>ラベンダー色の円柱を作成し、(11.125, 0, 0)に配置、スケールを(1, 4, 1)とします。</p>



<figure class="wp-block-image size-full is-resized"><a href="https://d9m.one/wp-content/uploads/2022/07/Pinball_001.png"><img decoding="async" src="https://d9m.one/wp-content/uploads/2022/07/Pinball_001.png" alt="" class="wp-image-587" width="658" height="475"/></a><figcaption>【打ち出し器作成】ラベンダー色の円柱を作成し、(11.125, 0, 0)に配置、スケールを(1, 4, 1)とする</figcaption></figure>



<ol class="wp-block-list"><li>ヒエラルキー左上の「＋」をクリックし、「3Dオブジェクト＞シリンダー」をクリック</li><li>「Plunger」と入力し、ENTERキーを押す</li><li>インスペクターの「Transform＞位置」を(11.125, 0, 0)に設定</li><li>インスペクターの「Transform＞スケール」を(1, 4, 1)に設定</li><li>プロジェクト左上の「＋」をクリックし、「マテリアル」をクリック</li><li>「matPlunger」と入力し、ENTERキーを押す</li><li>インスペクターの「アルベド＞カラーバー」をクリックし、色ダイアログの16進数を「CAB8D9」に設定</li><li>色ダイアログの右上にある「×」をクリック</li><li>プロジェクトの「matPlunger」をヒエラルキーの「Plunger」にドラッグ＆ドロップ</li><li>CTRLキーを押しながらSキーを押す</li></ol>



<h4 class="wp-block-heading"><span id="toc5">▷フリッパー作成</span></h4>



<p>フリッパーとして空オブジェクトを作成してプレハブ化し、<br>以下４つのプリミティブを子供として格納します。<br>緑色の円柱１：位置(0, 0, 0)、回転(90, 0, 0)、スケール(1, 0.5, 1)<br>緑色の円柱２：位置(3, -0.25, 0)、回転(90, 0, 0)、スケール(0.5, 0.5, 0.5)<br>緑色の箱１：位置(1.5, -0.25, 0)、回転(0, 0, 0)、スケール(3, 0.5, 1)<br>緑色の箱２：位置(1.5, 0, 0)、回転(0, 0, -9.4)、スケール(3, 0.5, 1)</p>



<figure class="wp-block-image size-full is-resized"><a href="https://d9m.one/wp-content/uploads/2022/07/Pinball_002.png"><img decoding="async" src="https://d9m.one/wp-content/uploads/2022/07/Pinball_002.png" alt="" class="wp-image-564" width="658" height="475"/></a><figcaption>【フリッパー作成】フリッパーとして空オブジェクトを作成してプレハブ化し、<br>以下４つのプリミティブを子供として格納する<br>緑色の円柱１：位置(0, 0, 0)、回転(90, 0, 0)、スケール(1, 0.5, 1)<br>緑色の円柱２：位置(3, -0.25, 0)、回転(90, 0, 0)、スケール(0.5, 0.5, 0.5)<br>緑色の箱１：位置(1.5, -0.25, 0)、回転(0, 0, 0)、スケール(3, 0.5, 1)<br>緑色の箱２：位置(1.5, 0, 0)、回転(0, 0, -9.4)、スケール(3, 0.5, 1)</figcaption></figure>



<ol class="wp-block-list"><li>ヒエラルキー左上の「＋」をクリックし、「空のオブジェクトを作成」をクリック</li><li>「Flipper」と入力し、ENTERキーを押す</li><li>インスペクターの「Transform＞縦の三点リーダー」をクリックし、リセットをクリック</li><li>ヒエラルキーの「Flipper」をプロジェクトの「Assets」にドラッグ＆ドロップ</li><li>プロジェクトの「Assets＞Flipper」をダブルクリック</li><li>ヒエラルキー左上の「＋」をクリックし、「3Dオブジェクト＞シリンダー」をクリック</li><li>インスペクターの「Transform＞位置」を(0, 0, 0)に設定</li><li>インスペクターの「Transform＞回転」を(90, 0, 0)に設定</li><li>インスペクターの「Transform＞スケール」を(1, 0.5, 1)に設定</li><li>ヒエラルキー左上の「＋」をクリックし、「3Dオブジェクト＞シリンダー」をクリック</li><li>インスペクターの「Transform＞位置」を(3, -0.25, 0)に設定</li><li>インスペクターの「Transform＞回転」を(90, 0, 0)に設定</li><li>インスペクターの「Transform＞スケール」を(0.5, 0.5, 0.5)に設定</li><li>ヒエラルキー左上の「＋」をクリックし、「3Dオブジェクト＞キューブ」をクリック</li><li>インスペクターの「Transform＞位置」を(1.5, -0.25, 0)に設定</li><li>インスペクターの「Transform＞スケール」を(3, 0.5, 1)に設定</li><li>ヒエラルキー左上の「＋」をクリックし、「3Dオブジェクト＞キューブ」をクリック</li><li>インスペクターの「Transform＞位置」を(1.5, 0, 0)に設定</li><li>インスペクターの「Transform＞回転」を(0, 0, -9.4)に設定</li><li>インスペクターの「Transform＞スケール」を(3, 0.5, 1)に設定</li><li>プロジェクト左上の「＋」をクリックし、「マテリアル」をクリック</li><li>「matFlipper」と入力し、ENTERキーを押す</li><li>インスペクターの「アルベド＞カラーバー」をクリックし、色ダイアログの16進数を「00FF00」に設定</li><li>色ダイアログの右上にある「×」をクリック</li><li>ヒエラルキーの「Flipper＞Cylinder」をクリック</li><li>SHIFTを押したまま、ヒエラルキーの「Flipper＞Cute (1)」をクリック</li><li>プロジェクトの「matFlipper」をインスペクターの「コンポーネントに追加」にドラッグ＆ドロップ</li><li>ヒエラルキー左上の「＜」をクリック</li><li>CTRLキーを押しながらSキーを押す</li></ol>



<h4 class="wp-block-heading"><span id="toc6">▷ターゲット作成</span></h4>



<p>黄色の箱を作成し、(0, 35, 0)に配置、回転を(0, 45, 0)、スケールを(1, 1, 1)としてプレハブ化します。</p>



<figure class="wp-block-image size-full is-resized"><a href="https://d9m.one/wp-content/uploads/2022/07/Pinball_003.png"><img decoding="async" src="https://d9m.one/wp-content/uploads/2022/07/Pinball_003.png" alt="" class="wp-image-565" width="658" height="475"/></a><figcaption>【ターゲット作成】黄色の箱を作成し、(0, 35, 0)に配置、回転を(0, 45, 0)、スケールを(1, 1, 1)としてプレハブ化する</figcaption></figure>



<ol class="wp-block-list"><li>ヒエラルキー左上の「＋」をクリックし、「3Dオブジェクト＞キューブ」をクリック</li><li>「Target」と入力し、ENTERキーを押す</li><li>インスペクターの「Transform＞位置」を(0, 35, 0)に設定</li><li>インスペクターの「Transform＞回転」を(0, 45, 0)に設定</li><li>インスペクターの「Transform＞スケール」を(1, 1, 1)に設定</li><li>プロジェクト左上の「＋」をクリックし、「マテリアル」をクリック</li><li>「matTarget」と入力し、ENTERキーを押す</li><li>インスペクターの「アルベド＞カラーバー」をクリックし、色ダイアログの16進数を「FFFF00」に設定</li><li>色ダイアログの右上にある「×」をクリック</li><li>プロジェクトの「matTarget」をヒエラルキーの「Target」にドラッグ＆ドロップ</li><li>ヒエラルキーの「Target」をプロジェクトの「Assets」にドラッグ＆ドロップ</li><li>CTRLキーを押しながらSキーを押す</li></ol>



<h4 class="wp-block-heading"><span id="toc7">▷バンパー作成</span></h4>



<p>茶色の円柱を作成し、(0, 27, 0)に配置、回転を(90, 0, 0)、スケールを(3, 0.5, 3)としてプレハブ化します。</p>



<figure class="wp-block-image size-full is-resized"><a href="https://d9m.one/wp-content/uploads/2022/07/Pinball_004.png"><img decoding="async" src="https://d9m.one/wp-content/uploads/2022/07/Pinball_004.png" alt="" class="wp-image-566" width="658" height="475"/></a><figcaption>【バンパー作成】茶色の円柱を作成し、(0, 27, 0)に配置、回転を(90, 0, 0)、スケールを(3, 0.5, 3)としてプレハブ化する</figcaption></figure>



<ol class="wp-block-list"><li>ヒエラルキー左上の「＋」をクリックし、「3Dオブジェクト＞シリンダー」をクリック</li><li>「Bumper」と入力し、ENTERキーを押す</li><li>インスペクターの「Transform＞位置」を(0, 27, 0)に設定</li><li>インスペクターの「Transform＞回転」を(90, 0, 0)に設定</li><li>インスペクターの「Transform＞スケール」を(3, 0.5, 3)に設定</li><li>プロジェクト左上の「＋」をクリックし、「マテリアル」をクリック</li><li>「matBumper」と入力し、ENTERキーを押す</li><li>インスペクターの「アルベド＞カラーバー」をクリックし、色ダイアログの16進数を「800000」に設定</li><li>色ダイアログの右上にある「×」をクリック</li><li>プロジェクトの「matBumper」をヒエラルキーの「Bumper」にドラッグ＆ドロップ</li><li>ヒエラルキーの「Bumper」をプロジェクトの「Assets」にドラッグ＆ドロップ</li><li>CTRLキーを押しながらSキーを押す</li></ol>



<h4 class="wp-block-heading"><span id="toc8">▷ミスエリア作成</span></h4>



<p>赤色の箱を作成し、(0, -6, 0)に配置、スケールを(20, 1, 1)とします。</p>



<figure class="wp-block-image size-full is-resized"><a href="https://d9m.one/wp-content/uploads/2022/07/Pinball_005.png"><img decoding="async" src="https://d9m.one/wp-content/uploads/2022/07/Pinball_005.png" alt="" class="wp-image-567" width="658" height="475"/></a><figcaption>【ミスエリア作成】赤色の箱を作成し、(0, -6, 0)に配置、スケールを(20, 1, 1)とする</figcaption></figure>



<ol class="wp-block-list"><li>ヒエラルキー左上の「＋」をクリックし、「3Dオブジェクト＞キューブ」をクリック</li><li>「WallMiss」と入力し、ENTERキーを押す</li><li>インスペクターの「Transform＞位置」を(0, -6, 0)に設定</li><li>インスペクターの「Transform＞スケール」を(20, 1, 1)に設定</li><li>プロジェクト左上の「＋」をクリックし、「マテリアル」をクリック</li><li>「matWallMiss」と入力し、ENTERキーを押す</li><li>インスペクターの「アルベド＞カラーバー」をクリックし、色ダイアログの16進数を「FF0000」に設定</li><li>色ダイアログの右上にある「×」をクリック</li><li>プロジェクトの「matWallMiss」をヒエラルキーの「WallMiss」にドラッグ＆ドロップ</li><li>CTRLキーを押しながらSキーを押す</li></ol>



<h4 class="wp-block-heading"><span id="toc9">▷シーン確認</span></h4>



<p>シーンカメラを動かし、作成したオブジェクトを確認します。</p>



<figure class="wp-block-image size-full is-resized"><a href="https://d9m.one/wp-content/uploads/2022/07/Pinball_006.png"><img decoding="async" src="https://d9m.one/wp-content/uploads/2022/07/Pinball_006.png" alt="" class="wp-image-571" width="658" height="475"/></a><figcaption>【シーン確認】シーンカメラを動かし、作成したオブジェクトを確認する</figcaption></figure>



<ol class="wp-block-list"><li>マウスホイールを手前に回転する</li><li>マウス右ボタンを押したまま、マウスを上下左右に動かす</li><li>マウス中央ボタンを押したまま、マウスを上下左右に動かす</li><li>上下左右キーを押す</li><li>以上を繰り返し、シーンに配置したオブジェクトを確認する</li></ol>



<h3 class="has-background has-medium-font-size wp-block-heading" style="background-color:#e5f7fd"><span id="toc10">●オブジェクト配置</span></h3>



<div style="height:16px" aria-hidden="true" class="wp-block-spacer"></div>



<h4 class="wp-block-heading"><span id="toc11">▷カメラ調整</span></h4>



<p>カメラを位置(0, 11, -40)、回転(350, 0, 0)、背景色(202080)とします。</p>



<figure class="wp-block-image size-full is-resized"><a href="https://d9m.one/wp-content/uploads/2022/07/Pinball_007.png"><img decoding="async" src="https://d9m.one/wp-content/uploads/2022/07/Pinball_007.png" alt="" class="wp-image-573" width="658" height="475"/></a><figcaption>【カメラ調整】カメラを位置(0, 11, -40)、回転(350, 0, 0)、背景色(202080)とする</figcaption></figure>



<ol class="wp-block-list"><li>ヒエラルキーの「Main Camera」をクリック</li><li>インスペクターの「Transform＞位置」を(0, 11 -40)に設定</li><li>インスペクターの「Transform＞回転」を(350, 0, 0)に設定</li><li>インスペクターの「Camera＞クリアフラグ」を「ソリッドカラー」に設定</li><li>インスペクターの「Camera＞背景」のカラーバーをクリックし、色ダイアログの16進数を「202080」に設定</li><li>色ダイアログの右上にある「×」をクリック</li><li>CTRLキーを押しながらSキーを押す</li><li>ゲームビューの「FreeAspect」をクリック</li><li>「9:16 Aspect」をクリック（無い場合は以下を操作）</li><li>左下の「＋」をクリック</li><li>ドロップダウン「タイプ」をクリックし、「アスペクト比」をクリック</li><li>幅＆高さの「X」に(9)、「Y」に(16)を入力</li><li>「OK」をクリック</li></ol>



<h4 class="wp-block-heading"><span id="toc12">▷左壁作成</span></h4>



<p>緑色の箱を作成し、(-10, 19, 0)に配置、スケールを(1, 43, 1)とします。</p>



<figure class="wp-block-image size-full is-resized"><a href="https://d9m.one/wp-content/uploads/2022/07/Pinball_008.png"><img decoding="async" src="https://d9m.one/wp-content/uploads/2022/07/Pinball_008.png" alt="" class="wp-image-574" width="658" height="475"/></a><figcaption>【左壁作成】緑色の箱を作成し、(-10, 19, 0)に配置、スケールを(1, 43, 1)とする</figcaption></figure>



<ol class="wp-block-list"><li>ヒエラルキー左上の「＋」をクリックし、「3Dオブジェクト＞キューブ」をクリック</li><li>「WallLeft」と入力し、ENTERキーを押す</li><li>インスペクターの「Transform＞縦の三点リーダー」をクリックし、リセットをクリック</li><li>インスペクターの「Transform＞位置」を(-10, 19, 0)に設定</li><li>インスペクターの「Transform＞スケール」を(1, 43, 1)に設定</li><li>プロジェクト左上の「＋」をクリックし、「マテリアル」をクリック</li><li>「matWall」と入力し、ENTERキーを押す</li><li>インスペクターの「アルベド＞カラーバー」をクリックし、色ダイアログの16進数を「008000」に設定</li><li>色ダイアログの右上にある「×」をクリック</li><li>プロジェクトの「matWall」をヒエラルキーの「WallLeft」にドラッグ＆ドロップ</li><li>CTRLキーを押しながらSキーを押す</li></ol>



<h4 class="wp-block-heading"><span id="toc13">▷右壁作成</span></h4>



<p>緑色の箱を２つ作成し、以下のように配置します。<br>箱１：位置(10, 17, 0)、スケールを(1, 39, 1)<br>箱２：位置(12.25, 20, 0)、スケールを(1, 41, 1)</p>



<figure class="wp-block-image size-full is-resized"><a href="https://d9m.one/wp-content/uploads/2022/07/Pinball_009.png"><img decoding="async" src="https://d9m.one/wp-content/uploads/2022/07/Pinball_009.png" alt="" class="wp-image-575" width="658" height="475"/></a><figcaption>【右壁作成】緑色の箱を２つ作成し、以下のように配置<br>箱１：位置(10, 17, 0)、スケールを(1, 39, 1)<br>箱２：位置(12.25, 20, 0)、スケールを(1, 41, 1)</figcaption></figure>



<ol class="wp-block-list"><li>ヒエラルキーの「WallLeft」をクリックし、CTRLを押しながらDキーを押す</li><li>F2キーを押して「WallRight1」と入力し、ENTERキーを押す</li><li>インスペクターの「Transform＞位置」を(10, 17, 0)に設定</li><li>インスペクターの「Transform＞スケール」を(1, 39, 1)に設定</li><li>ヒエラルキーの「WallRight1」をクリックし、CTRLを押しながらDキーを押す</li><li>F2キーを押して「WallRight2」と入力し、ENTERキーを押す</li><li>インスペクターの「Transform＞位置」を(12.25, 20, 0)に設定</li><li>インスペクターの「Transform＞スケール」を(1, 41, 1)に設定</li><li>CTRLキーを押しながらSキーを押す</li></ol>



<h4 class="wp-block-heading"><span id="toc14">▷上壁作成</span></h4>



<p>緑色の箱を２つ作成し、以下のように配置します。<br>箱１：位置(-5, 42, 0)、回転(0, 0, 290)、スケールを(1, 11, 1)<br>箱２：位置(6, 41.65, 0)、回転(0, 0, 70)、スケールを(1, 13, 1)</p>



<figure class="wp-block-image size-full is-resized"><a href="https://d9m.one/wp-content/uploads/2022/07/Pinball_010.png"><img decoding="async" src="https://d9m.one/wp-content/uploads/2022/07/Pinball_010.png" alt="" class="wp-image-576" width="658" height="475"/></a><figcaption>【上壁作成】緑色の箱を２つ作成し、以下のように配置<br>箱１：位置(-5, 42, 0)、回転(0, 0, 290)、スケールを(1, 11, 1)<br>箱２：位置(6, 41.65, 0)、回転(0, 0, 70)、スケールを(1, 13, 1)</figcaption></figure>



<ol class="wp-block-list"><li>ヒエラルキーの「WallLeft」をクリックし、CTRLを押しながらDキーを押す</li><li>F2キーを押して「WallTopL」と入力し、ENTERキーを押す</li><li>インスペクターの「Transform＞位置」を(-5, 42, 0)に設定</li><li>インスペクターの「Transform＞回転」を(0, 0, 290)に設定</li><li>インスペクターの「Transform＞スケール」を(1, 11, 1)に設定</li><li>ヒエラルキーの「WallTopL」をクリックし、CTRLを押しながらDキーを押す</li><li>F2キーを押して「WallTopR」と入力し、ENTERキーを押す</li><li>インスペクターの「Transform＞位置」を(6, 41.65, 0)に設定</li><li>インスペクターの「Transform＞回転」を(0, 0, 70)に設定</li><li>インスペクターの「Transform＞スケール」を(1, 13, 1)に設定</li><li>CTRLキーを押しながらSキーを押す</li></ol>



<h4 class="wp-block-heading"><span id="toc15">▷フリッパー左側の壁作成</span></h4>



<p>緑色の箱を２つ作成し、以下のように配置します。<br>箱１：位置(-7.75, 3.5, 0)、回転(0, 0, 0)、スケールを(1, 5, 1)<br>箱２：位置(-6, 0.7, 0)、回転(0, 0, 250)、スケールを(1, 4, 1)</p>



<figure class="wp-block-image size-full is-resized"><a href="https://d9m.one/wp-content/uploads/2022/07/Pinball_011.png"><img decoding="async" src="https://d9m.one/wp-content/uploads/2022/07/Pinball_011.png" alt="" class="wp-image-577" width="658" height="475"/></a><figcaption>【フリッパー左側の壁作成】緑色の箱を２つ作成し、以下のように配置<br>箱１：位置(-7.75, 3.5, 0)、回転(0, 0, 0)、スケールを(1, 5, 1)<br>箱２：位置(-6, 0.7, 0)、回転(0, 0, 250)、スケールを(1, 4, 1)</figcaption></figure>



<ol class="wp-block-list"><li>ヒエラルキーの「WallLeft」をクリックし、CTRLを押しながらDキーを押す</li><li>F2キーを押して「WallFlipL1」と入力し、ENTERキーを押す</li><li>インスペクターの「Transform＞位置」を(-7.75, 3.5, 0)に設定</li><li>インスペクターの「Transform＞回転」を(0, 0, 0)に設定</li><li>インスペクターの「Transform＞スケール」を(1, 5, 1)に設定</li><li>ヒエラルキーの「WallFlipL1」をクリックし、CTRLを押しながらDキーを押す</li><li>F2キーを押して「WallFlipL2」と入力し、ENTERキーを押す</li><li>インスペクターの「Transform＞位置」を(-6, 0.7, 0)に設定</li><li>インスペクターの「Transform＞回転」を(0, 0, 250)に設定</li><li>インスペクターの「Transform＞スケール」を(1, 4, 1)に設定</li><li>CTRLキーを押しながらSキーを押す</li></ol>



<h4 class="wp-block-heading"><span id="toc16">▷フリッパー右側の壁作成</span></h4>



<p>緑色の箱を２つ作成し、以下のように配置します。<br>箱１：位置(-7.75, 3.5, 0)、回転(0, 0, 0)、スケールを(1, 5, 1)<br>箱２：位置(-6, 0.7, 0)、回転(0, 0, 290)、スケールを(1, 4, 1)</p>



<figure class="wp-block-image size-full is-resized"><a href="https://d9m.one/wp-content/uploads/2022/07/Pinball_012.png"><img decoding="async" src="https://d9m.one/wp-content/uploads/2022/07/Pinball_012.png" alt="" class="wp-image-580" width="658" height="475"/></a><figcaption>【フリッパー右側の壁作成】緑色の箱を２つ作成し、以下のように配置<br>箱１：位置(-7.75, 3.5, 0)、回転(0, 0, 0)、スケールを(1, 5, 1)<br>箱２：位置(-6, 0.7, 0)、回転(0, 0, 290)、スケールを(1, 4, 1)</figcaption></figure>



<ol class="wp-block-list"><li>ヒエラルキーの「WallFlipL1」をクリック</li><li>CTRLを押しながらヒエラルキーの「WallFlipL2」をクリック</li><li>CTRLを押しながらDキーを押す</li><li>ヒエラルキーの「WallFlipL1 (1)」をクリック</li><li>F2キーを押して「WallFlipR1」と入力し、ENTERキーを押す</li><li>インスペクターの「Transform＞位置＞X」を(7.75)に設定</li><li>ヒエラルキーの「WallFlipL2 (1)」をクリック</li><li>F2キーを押して「WallFlipR2」と入力し、ENTERキーを押す</li><li>インスペクターの「Transform＞位置＞X」を(6)に設定</li><li>インスペクターの「Transform＞回転＞Z」を(290)に設定</li><li>CTRLキーを押しながらSキーを押す</li></ol>



<h4 class="wp-block-heading"><span id="toc17">▷下壁作成</span></h4>



<p>緑色の箱を２つ作成し、以下のように配置します。<br>箱１：位置(-5.5, -2, 0)、回転(0, 0, 70)、スケールを(1, 10, 1)<br>箱２：位置(5.5, -2, 0)、回転(0, 0, 290)、スケールを(1, 10, 1)</p>



<figure class="wp-block-image size-full is-resized"><a href="https://d9m.one/wp-content/uploads/2022/07/Pinball_013.png"><img decoding="async" src="https://d9m.one/wp-content/uploads/2022/07/Pinball_013.png" alt="" class="wp-image-581" width="658" height="475"/></a><figcaption>【下壁作成】緑色の箱を２つ作成し、以下のように配置<br>箱１：位置(-5.5, -2, 0)、回転(0, 0, 70)、スケールを(1, 10, 1)<br>箱２：位置(5.5, -2, 0)、回転(0, 0, 290)、スケールを(1, 10, 1)</figcaption></figure>



<ol class="wp-block-list"><li>ヒエラルキーの「WallLeft」をクリックし、CTRLを押しながらDキーを押す</li><li>F2キーを押して「WallBottomL」と入力し、ENTERキーを押す</li><li>インスペクターの「Transform＞位置」を(-5.5, -2, 0)に設定</li><li>インスペクターの「Transform＞回転」を(0, 0, 70)に設定</li><li>インスペクターの「Transform＞スケール」を(1, 10, 1)に設定</li><li>ヒエラルキーの「WallBottomL」をクリックし、CTRLを押しながらDキーを押す</li><li>F2キーを押して「WallBottomR」と入力し、ENTERキーを押す</li><li>インスペクターの「Transform＞位置＞X」を(5.5)に設定</li><li>インスペクターの「Transform＞回転＞Z」を(290)に設定</li><li>CTRLキーを押しながらSキーを押す</li></ol>



<h4 class="wp-block-heading"><span id="toc18">▷フリッパー配置</span></h4>



<p>フリッパーを複製し、以下のように配置します。<br>フリッパー１：位置(-3.7, 0, 0)、回転(0, 0, -18)<br>フリッパー２：位置(3.7, 0, 0)、回転(0, 180, -18)</p>



<figure class="wp-block-image size-full is-resized"><a href="https://d9m.one/wp-content/uploads/2022/07/Pinball_014.png"><img decoding="async" src="https://d9m.one/wp-content/uploads/2022/07/Pinball_014.png" alt="" class="wp-image-582" width="658" height="475"/></a><figcaption>【フリッパー配置】フリッパーを複製し、以下のように配置<br>フリッパー１：位置(-3.7, 0, 0)、回転(0, 0, -18)<br>フリッパー２：位置(3.7, 0, 0)、回転(0, 180, -18)</figcaption></figure>



<ol class="wp-block-list"><li>ヒエラルキーの「Flipper」をクリック</li><li>F2キーを押して「FlipperL」と入力し、ENTERキーを押す</li><li>インスペクターの「Transform＞位置」を(-3.7, 0, 0)に設定</li><li>インスペクターの「Transform＞回転」を(0, 0, -18)に設定</li><li>ヒエラルキーの「FlipperL」をクリック</li><li>CTRLを押しながらDキーを押す</li><li>F2キーを押して「FlipperR」と入力し、ENTERキーを押す</li><li>インスペクターの「Transform＞位置＞X」を(3.7)に設定</li><li>インスペクターの「Transform＞回転＞Y」を(180)に設定</li><li>CTRLキーを押しながらSキーを押す</li></ol>



<h4 class="wp-block-heading"><span id="toc19">▷ターゲット配置</span></h4>



<p>ターゲットを複製し、以下のように配置します。<br>ターゲット１：位置(0, 35, 0)<br>ターゲット２：位置(-6, 30, 0)<br>ターゲット３：位置(6, 30, 0)<br>ターゲット４：位置(-4, 20, 0)<br>ターゲット５：位置(4, 20, 0)</p>



<figure class="wp-block-image size-full is-resized"><a href="https://d9m.one/wp-content/uploads/2022/07/Pinball_015.png"><img decoding="async" src="https://d9m.one/wp-content/uploads/2022/07/Pinball_015.png" alt="" class="wp-image-583" width="658" height="475"/></a><figcaption>【ターゲット配置】ターゲットを複製し、以下のように配置<br>ターゲット１：位置(0, 35, 0)<br>ターゲット２：位置(-6, 30, 0)<br>ターゲット３：位置(6, 30, 0)<br>ターゲット４：位置(-4, 20, 0)<br>ターゲット５：位置(4, 20, 0)</figcaption></figure>



<ol class="wp-block-list"><li>ヒエラルキーの「Target」をクリック</li><li>CTRLを押しながらDキーを押す</li><li>インスペクターの「Transform＞位置」を(-6, 30, 0)に設定</li><li>ヒエラルキーの「Target (1)」をクリック</li><li>CTRLを押しながらDキーを押す</li><li>インスペクターの「Transform＞位置＞X」を(6)に設定</li><li>ヒエラルキーの「Target (2)」をクリック</li><li>CTRLを押しながらDキーを押す</li><li>インスペクターの「Transform＞位置」を(-4, 20, 0)に設定</li><li>ヒエラルキーの「Target (3)」をクリック</li><li>CTRLを押しながらDキーを押す</li><li>インスペクターの「Transform＞位置＞X」を(4)に設定</li><li>CTRLキーを押しながらSキーを押す</li></ol>



<h4 class="wp-block-heading"><span id="toc20">▷バンパー配置</span></h4>



<p>フリッパーを複製し、以下のように配置します。<br>バンパー１：位置(0, 27, 0)<br>バンパー２：位置(-5, 10, 0)<br>バンパー３：位置(5, 10, 0)</p>



<figure class="wp-block-image size-full is-resized"><a href="https://d9m.one/wp-content/uploads/2022/07/Pinball_016.png"><img decoding="async" src="https://d9m.one/wp-content/uploads/2022/07/Pinball_016.png" alt="" class="wp-image-608" width="658" height="475" srcset="https://d9m.one/wp-content/uploads/2022/07/Pinball_016.png 877w, https://d9m.one/wp-content/uploads/2022/07/Pinball_016-300x217.png 300w, https://d9m.one/wp-content/uploads/2022/07/Pinball_016-768x554.png 768w" sizes="(max-width: 658px) 100vw, 658px" /></a><figcaption>【バンパー配置】フリッパーを複製し、以下のように配置<br>バンパー１：位置(0, 27, 0)<br>バンパー２：位置(-5, 10, 0)<br>バンパー３：位置(5, 10, 0)</figcaption></figure>



<ol class="wp-block-list"><li>ヒエラルキーの「Bumper」をクリック</li><li>CTRLを押しながらDキーを押す</li><li>インスペクターの「Transform＞位置」を(-5, 10, 0)に設定</li><li>ヒエラルキーの「Bumper (1)」をクリック</li><li>CTRLを押しながらDキーを押す</li><li>インスペクターの「Transform＞位置＞X」を(5)に設定</li><li>CTRLキーを押しながらSキーを押す</li></ol>



<h3 class="has-background has-medium-font-size wp-block-heading" style="background-color:#e5f7fd"><span id="toc21">●オブジェクト整理</span></h3>



<div style="height:16px" aria-hidden="true" class="wp-block-spacer"></div>



<h4 class="wp-block-heading"><span id="toc22">▷壁整理</span></h4>



<p>空オブジェクトを作成し、「全ての壁」を格納します。</p>



<figure class="wp-block-image size-full is-resized"><a href="https://d9m.one/wp-content/uploads/2022/07/Pinball_017.png"><img decoding="async" src="https://d9m.one/wp-content/uploads/2022/07/Pinball_017.png" alt="" class="wp-image-584" width="658" height="475"/></a><figcaption>【壁整理】空オブジェクトを作成し、「全ての壁」を格納</figcaption></figure>



<ol class="wp-block-list"><li>ヒエラルキー左上「＋」をクリックし、「空のオブジェクトを作成」をクリック</li><li>「Walls」と入力し、ENTERキーを押す</li><li>インスペクターの「Transform＞縦の三点リーダー」をクリックし、リセットをクリック</li><li>ヒエラルキーの「WallLeft」をクリック</li><li>CTRLを押したまま、ヒエラルキーの「WallRight1」をクリック</li><li>CTRLを押したまま、ヒエラルキーの「WallRight2」をクリック</li><li>CTRLを押したまま、ヒエラルキーの「WallTopL」をクリック</li><li>CTRLを押したまま、ヒエラルキーの「WallTopR」をクリック</li><li>CTRLを押したまま、ヒエラルキーの「WallFlipL1」をクリック</li><li>CTRLを押したまま、ヒエラルキーの「WallFlipL2」をクリック</li><li>CTRLを押したまま、ヒエラルキーの「WallFlipR1」をクリック</li><li>CTRLを押したまま、ヒエラルキーの「WallFlipR2」をクリック</li><li>CTRLを押したまま、ヒエラルキーの「WallBottomL」をクリック</li><li>CTRLを押したまま、ヒエラルキーの「WallBottomR」をクリック</li><li>ヒエラルキーの選択ゲームオブジェクトを「Walls」にドラッグ＆ドロップ</li><li>ヒエラルキーの「Walls」左にある三角形をクリック</li><li>CTRLキーを押しながらSキーを押す</li></ol>



<h4 class="wp-block-heading"><span id="toc23">▷ターゲット整理</span></h4>



<p>空オブジェクトを作成し、「全ターゲット」を格納します。</p>



<figure class="wp-block-image size-full is-resized"><a href="https://d9m.one/wp-content/uploads/2022/07/Pinball_018.png"><img decoding="async" src="https://d9m.one/wp-content/uploads/2022/07/Pinball_018.png" alt="" class="wp-image-585" width="658" height="475"/></a><figcaption>【ターゲット整理】空オブジェクトを作成し、「全ターゲット」を格納</figcaption></figure>



<ol class="wp-block-list"><li>ヒエラルキー左上「＋」をクリックし、「空のオブジェクトを作成」をクリック</li><li>「Targets」と入力し、ENTERキーを押す</li><li>インスペクターの「Transform＞縦の三点リーダー」をクリックし、リセットをクリック</li><li>ヒエラルキーの「Target」をクリック</li><li>CTRLを押したまま、ヒエラルキーの「Target (1)」をクリック</li><li>CTRLを押したまま、ヒエラルキーの「Target (2)」をクリック</li><li>CTRLを押したまま、ヒエラルキーの「Target (3)」をクリック</li><li>CTRLを押したまま、ヒエラルキーの「Target (4)」をクリック</li><li>ヒエラルキーの選択ゲームオブジェクトを「Targets」にドラッグ＆ドロップ</li><li>ヒエラルキーの「Targets」左にある三角形をクリック</li><li>CTRLキーを押しながらSキーを押す</li></ol>



<h4 class="wp-block-heading"><span id="toc24">▷バンパー整理</span></h4>



<p>空オブジェクトを作成し、「全バンパー」を格納します。</p>



<figure class="wp-block-image size-full is-resized"><a href="https://d9m.one/wp-content/uploads/2022/07/Pinball_019.png"><img decoding="async" src="https://d9m.one/wp-content/uploads/2022/07/Pinball_019.png" alt="" class="wp-image-586" width="658" height="475"/></a><figcaption>【バンパー整理】空オブジェクトを作成し、「全バンパー」を格納</figcaption></figure>



<ol class="wp-block-list"><li>ヒエラルキー左上「＋」をクリックし、「空のオブジェクトを作成」をクリック</li><li>「Bumpers」と入力し、ENTERキーを押す</li><li>インスペクターの「Transform＞縦の三点リーダー」をクリックし、リセットをクリック</li><li>ヒエラルキーの「Bumper」をクリック</li><li>CTRLを押したまま、ヒエラルキーの「Bumper(1)」をクリック</li><li>CTRLを押したまま、ヒエラルキーの「Bumper(2)」をクリック</li><li>ヒエラルキーの選択ゲームオブジェクトを「Bumpers」にドラッグ＆ドロップ</li><li>ヒエラルキーの「Bumpers」左にある三角形をクリック</li><li>CTRLキーを押しながらSキーを押す</li></ol>



<h4 class="wp-block-heading"><span id="toc25">▷プロジェクト整理</span></h4>



<p>マテリアル用、プレハブ用の格納フォルダを作成して移動します。</p>



<figure class="wp-block-image size-full is-resized"><a href="https://d9m.one/wp-content/uploads/2022/07/Pinball_020.png"><img decoding="async" src="https://d9m.one/wp-content/uploads/2022/07/Pinball_020.png" alt="" class="wp-image-613" width="658" height="475" srcset="https://d9m.one/wp-content/uploads/2022/07/Pinball_020.png 877w, https://d9m.one/wp-content/uploads/2022/07/Pinball_020-300x217.png 300w, https://d9m.one/wp-content/uploads/2022/07/Pinball_020-768x554.png 768w" sizes="(max-width: 658px) 100vw, 658px" /></a><figcaption>【プロジェクト整理】マテリアル用、プレハブ用の格納フォルダを作成して移動</figcaption></figure>



<ol class="wp-block-list"><li>プロジェクト左上の「＋」をクリックし、「フォルダー」をクリック</li><li>「Materials」と入力し、ENTERキーを押す</li><li>プロジェクトの「matBall」をクリック</li><li>CTRLを押したまま「matBumper」をクリック</li><li>CTRLを押したまま「matFlipper」をクリック</li><li>CTRLを押したまま「matPlunger」をクリック</li><li>CTRLを押したまま「matTarget」をクリック</li><li>CTRLを押したまま「matWall」をクリック</li><li>CTRLを押したまま「matWallMiss」をクリック</li><li>プロジェクトで選択中のアセットを「Assets＞Materials」にドラッグ＆ドロップ</li><li>プロジェクトの「Assets」をクリック</li><li>プロジェクト左上の「＋」をクリックし、「フォルダー」をクリック</li><li>「Prefabs」と入力し、ENTERキーを押す</li><li>プロジェクトの「Bumperr」を「Assets＞Prefabs」にドラッグ＆ドロップ</li><li>プロジェクトの「Flipper」を「Assets＞Prefabs」にドラッグ＆ドロップ</li><li>プロジェクトの「Target」を「Assets＞Prefabs」にドラッグ＆ドロップ</li></ol>



<h2 class="has-background has-large-font-size wp-block-heading" style="background-color:#f1e0f8;font-style:normal;font-weight:700"><span id="toc26">■オブジェクト機能</span></h2>



<div style="height:16px" aria-hidden="true" class="wp-block-spacer"></div>



<h3 class="has-background has-medium-font-size wp-block-heading" style="background-color:#e5f7fd"><span id="toc27">●プレイヤー制御</span></h3>



<div style="height:16px" aria-hidden="true" class="wp-block-spacer"></div>



<h4 class="wp-block-heading"><span id="toc28">▷スクリプト整理</span></h4>



<p>スクリプト格納用のフォルダを作成します。</p>



<figure class="wp-block-image size-full is-resized"><a href="https://d9m.one/wp-content/uploads/2022/07/Pinball_021.png"><img decoding="async" src="https://d9m.one/wp-content/uploads/2022/07/Pinball_021.png" alt="" class="wp-image-614" width="658" height="475" srcset="https://d9m.one/wp-content/uploads/2022/07/Pinball_021.png 877w, https://d9m.one/wp-content/uploads/2022/07/Pinball_021-300x217.png 300w, https://d9m.one/wp-content/uploads/2022/07/Pinball_021-768x554.png 768w" sizes="(max-width: 658px) 100vw, 658px" /></a><figcaption>【スクリプト整理】スクリプト格納用のフォルダを作成</figcaption></figure>



<ol class="wp-block-list"><li>プロジェクト左上の「＋」をクリックし、「フォルダー」をクリック</li><li>「Scripts」と入力し、ENTERキーを押す</li></ol>



<h4 class="wp-block-heading"><span id="toc29">▷玉物理設定</span></h4>



<p>玉にRigidbody「質量(0.7)、衝突判定(連続的かつ動的)、Z位置固定」として割り当て、物理マテリアルを弾性力(0.3)として割り当てます。</p>



<figure class="wp-block-image size-full is-resized"><a href="https://d9m.one/wp-content/uploads/2022/07/Pinball_022.png"><img decoding="async" src="https://d9m.one/wp-content/uploads/2022/07/Pinball_022.png" alt="" class="wp-image-615" width="658" height="475" srcset="https://d9m.one/wp-content/uploads/2022/07/Pinball_022.png 877w, https://d9m.one/wp-content/uploads/2022/07/Pinball_022-300x217.png 300w, https://d9m.one/wp-content/uploads/2022/07/Pinball_022-768x554.png 768w" sizes="(max-width: 658px) 100vw, 658px" /></a><figcaption>【玉物理設定】玉にRigidbody「質量(0.7)、衝突判定(連続的かつ動的)、Z位置固定」として割り当て、物理マテリアルを弾性力(0.3)として割り当てる</figcaption></figure>



<ol class="wp-block-list"><li>ヒエラルキーの「Ball」をクリック</li><li>インスペクターの「コンポーネントを追加」をクリックし、Physics＞Rigidbodyをクリック</li><li>インスペクターの「Rigidbody＞質量」を(0.7)に設定</li><li>インスペクターの「Rigidbody＞衝突判定」を(連続的かつ動的)に設定</li><li>インスペクターの「Rigidbody＞Constraints＞位置を固定＞Z」をチェック</li><li>プロジェクトの「Assets」を右クリックし、「作成＞物理マテリアル」をクリック</li><li>「Friction」と入力し、ENTERキーを押す</li><li>インスペクターの弾性力を(0.3)に設定</li><li>プロジェクトの「Friction」をヒエラルキーの「Ball」にドラッグ＆ドロップ</li><li>CTRLキーを押しながらSキーを押す</li></ol>



<h4 class="wp-block-heading"><span id="toc30">▷打ち出し器物理設定</span></h4>



<p>打ち出し器にRigidbodyを割り当て、Is Kinematic(あり)、衝突判定(連続的かつ動的)とします。</p>



<figure class="wp-block-image size-full is-resized"><a href="https://d9m.one/wp-content/uploads/2022/07/Pinball_023.png"><img decoding="async" src="https://d9m.one/wp-content/uploads/2022/07/Pinball_023.png" alt="" class="wp-image-616" width="658" height="475" srcset="https://d9m.one/wp-content/uploads/2022/07/Pinball_023.png 877w, https://d9m.one/wp-content/uploads/2022/07/Pinball_023-300x217.png 300w, https://d9m.one/wp-content/uploads/2022/07/Pinball_023-768x554.png 768w" sizes="(max-width: 658px) 100vw, 658px" /></a><figcaption>【打ち出し器物理設定】打ち出し器にRigidbodyを割り当て、Is Kinematic(あり)、衝突判定(連続的かつ動的)とする</figcaption></figure>



<ol class="wp-block-list"><li>ヒエラルキーの「Plunger」をクリック</li><li>インスペクターの「コンポーネントを追加」をクリックし、Physics＞Rigidbodyをクリック</li><li>インスペクターの「Rigidbody＞Is Kinematic」をチェック</li><li>インスペクターの「Rigidbody＞衝突判定」を(連続的かつ動的)に設定</li><li>CTRLキーを押しながらSキーを押す</li></ol>



<h4 class="wp-block-heading"><span id="toc31">▷制御スクリプト作成</span></h4>



<p>スクリプト「GameManager」を作成し、玉に割り当てます。</p>



<figure class="wp-block-image size-full is-resized"><a href="https://d9m.one/wp-content/uploads/2022/07/Pinball_024.png"><img decoding="async" src="https://d9m.one/wp-content/uploads/2022/07/Pinball_024.png" alt="" class="wp-image-619" width="658" height="475" srcset="https://d9m.one/wp-content/uploads/2022/07/Pinball_024.png 877w, https://d9m.one/wp-content/uploads/2022/07/Pinball_024-300x217.png 300w, https://d9m.one/wp-content/uploads/2022/07/Pinball_024-768x554.png 768w" sizes="(max-width: 658px) 100vw, 658px" /></a><figcaption>【打ち出し器制御】スクリプト「GameManager」を作成し、玉に割り当てる</figcaption></figure>



<ol class="wp-block-list"><li>プロジェクトの「Assets＞Scripts」を右クリックし、「作成＞C# スクリプト」をクリック</li><li>「GameManager」と入力し、ENTERキーを押す</li><li>プロジェクトの「GameManager」をヒエラルキーの「Ball」にドラッグ＆ドロップ</li><li>CTRLキーを押しながらSキーを押す</li></ol>



<h4 class="wp-block-heading"><span id="toc32">▷打ち出し器制御</span></h4>



<p>スペースを押している間は1フレームに0.5の速度で最大0まで上昇、離している間は1フレームに1の速度で最小-3.5まで下降させます。</p>



<ol class="wp-block-list"><li>プロジェクトの「Assets＞Scripts＞GameManager」をダブルクリック</li><li>スクリプトを以下のように記述</li></ol>



<div class="hcb_wrap"><pre class="prism line-numbers lang-plain" data-file="GameManager.cs"><code>using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class GameManager : MonoBehaviour
{
    public GameObject plunger;

    float plungerY = 3.5f;

    // Start is called before the first frame update
    void Start()
    {

    }

    // Update is called once per frame
    void Update()
    {
        Vector3 pos = plunger.transform.position;
        if (Input.GetAxis(&quot;Jump&quot;) &lt;= 0)
        {
            plungerY = Mathf.Clamp(plungerY + 0.5f, -3.5f, 0);
            pos.y = plungerY;
        }
        if (Input.GetAxis(&quot;Jump&quot;) &gt; 0)
        {
            plungerY = Mathf.Clamp(plungerY - 1, -3.5f, 0);
            pos.y = plungerY;
        }
        Rigidbody rb = plunger.GetComponent&lt;Rigidbody&gt;();
        rb.MovePosition(pos);
    }
}</code></pre></div>



<h4 class="wp-block-heading"><span id="toc33">▷打ち出し器割り当て</span></h4>



<p>GameManagerの参照に打ち出し器を割り当てます。</p>



<figure class="wp-block-image size-full is-resized"><a href="https://d9m.one/wp-content/uploads/2022/07/Pinball_025.png"><img decoding="async" src="https://d9m.one/wp-content/uploads/2022/07/Pinball_025.png" alt="" class="wp-image-620" width="658" height="475" srcset="https://d9m.one/wp-content/uploads/2022/07/Pinball_025.png 877w, https://d9m.one/wp-content/uploads/2022/07/Pinball_025-300x217.png 300w, https://d9m.one/wp-content/uploads/2022/07/Pinball_025-768x554.png 768w" sizes="(max-width: 658px) 100vw, 658px" /></a><figcaption>【打ち出し器割り当て】GameManagerの参照に打ち出し器を割り当てる</figcaption></figure>



<ol class="wp-block-list"><li>ヒエラルキーの「Ball」をクリック</li><li>ヒエラルキーの「Plumger」をインスペクターの「GameManager＞Plunger」にドラッグ＆ドロップ</li><li>CTRLキーを押しながらSキーを押す</li></ol>



<h4 class="wp-block-heading"><span id="toc34">▷打ち出し器制御確認</span></h4>



<p>スペースキーで打ち出し器を操作できることを確認します。</p>



<figure class="wp-block-image size-full is-resized"><a href="https://d9m.one/wp-content/uploads/2022/07/Pinball_026.png"><img decoding="async" src="https://d9m.one/wp-content/uploads/2022/07/Pinball_026.png" alt="" class="wp-image-621" width="658" height="475" srcset="https://d9m.one/wp-content/uploads/2022/07/Pinball_026.png 877w, https://d9m.one/wp-content/uploads/2022/07/Pinball_026-300x217.png 300w, https://d9m.one/wp-content/uploads/2022/07/Pinball_026-768x554.png 768w" sizes="(max-width: 658px) 100vw, 658px" /></a><figcaption>【打ち出し器制御確認】スペースキーで打ち出し器を操作できることを確認</figcaption></figure>



<ol class="wp-block-list"><li>エディタ上中央の「▶」をクリック</li><li>スペースキーを押す</li><li>打ち出し器が手前に移動することを確認</li><li>スペースキーを離す</li><li>打ち出し器が元の場所に戻り、球が打ち出される事を確認</li><li>エディタ上中央の「▶」をクリック</li></ol>



<h4 class="wp-block-heading"><span id="toc35">▷フリッパー物理設定</span></h4>



<p>フリッパーにRigidbodyを割り当て、Is Kinematic(あり)、衝突判定(連続的かつ動的)とします。</p>



<figure class="wp-block-image size-full is-resized"><a href="https://d9m.one/wp-content/uploads/2022/07/Pinball_027.png"><img decoding="async" src="https://d9m.one/wp-content/uploads/2022/07/Pinball_027.png" alt="" class="wp-image-622" width="658" height="475" srcset="https://d9m.one/wp-content/uploads/2022/07/Pinball_027.png 877w, https://d9m.one/wp-content/uploads/2022/07/Pinball_027-300x217.png 300w, https://d9m.one/wp-content/uploads/2022/07/Pinball_027-768x554.png 768w" sizes="(max-width: 658px) 100vw, 658px" /></a><figcaption>【フリッパー物理設定】フリッパーにRigidbodyを割り当て、Is Kinematic(あり)、衝突判定(連続的かつ動的)とする</figcaption></figure>



<ol class="wp-block-list"><li>プロジェクトの「Assets＞Prefabs＞Flipper」をダブルクリック</li><li>インスペクターの「コンポーネントを追加」をクリックし、Physics＞Rigidbodyをクリック</li><li>インスペクターの「Rigidbody＞Is Kinematic」をチェック</li><li>インスペクターの「Rigidbody＞衝突判定」を(連続的かつ動的)に設定</li><li>ヒエラルキーの左上にある「＜」をクリック</li></ol>



<ol class="wp-block-list"><li>プロジェクトの「Assets＞Scripts＞GameManager」をダブルクリック</li><li>スクリプトを以下のように記述</li></ol>



<h4 class="wp-block-heading"><span id="toc36">▷フリッパー制御</span></h4>



<p>以下の仕様でスクリプトを記述します。</p>



<ul class="wp-block-list"><li>左クリックで左フリッパー、右クリックで右フリッパーをZ軸を1フレーム16度の速度で30度まで動かす</li><li>押されていない時はZ軸を1フレーム16度の速度で-18度まで動かす</li></ul>



<div class="hcb_wrap"><pre class="prism line-numbers lang-plain" data-file="GameManager.cs"><code>using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class GameManager : MonoBehaviour
{
    public GameObject plunger;
    public GameObject flipperL;
    public GameObject flipperR;

    float plungerY = 3.5f;
    float[] angle = {0, 0};

    // Start is called before the first frame update
    void Start()
    {

    }

    // Update is called once per frame
    void Update()
    {
        Vector3 pos = plunger.transform.position;
        if (Input.GetAxis(&quot;Jump&quot;) &lt;= 0)
        {
            plungerY = Mathf.Clamp(plungerY + 0.5f, -3.5f, 0);
            pos.y = plungerY;
        }
        if (Input.GetAxis(&quot;Jump&quot;) &gt; 0)
        {
            plungerY = Mathf.Clamp(plungerY - 1, -3.5f, 0);
            pos.y = plungerY;
        }
        Rigidbody rb = plunger.GetComponent&lt;Rigidbody&gt;();
        rb.MovePosition(pos);

        FlipAction(0);
        FlipAction(1);
    }

    void FlipAction(int button)
    {
        if (Input.GetMouseButton(button) == true)
        {
            angle[button] += 16;
        }
        else
        {
            angle[button] -= 16;
        }
        angle[button] = Mathf.Clamp(angle[button], -18, 30);

        GameObject flipper;
        if (button == 0)
        {
            flipper = flipperL;
        }
        else
        {
            flipper = flipperR;
        }
        Rigidbody rb = flipper.GetComponent&lt;Rigidbody&gt;();

        Vector3 rot = flipper.transform.rotation.eulerAngles;
        rot.z = angle[button];
        rb.MoveRotation(Quaternion.Euler(rot));
    }
}</code></pre></div>



<h4 class="wp-block-heading"><span id="toc37">▷フリッパー割り当て</span></h4>



<p>GameManagerの参照にフリッパーを割り当てます。</p>



<figure class="wp-block-image size-full is-resized"><a href="https://d9m.one/wp-content/uploads/2022/07/Pinball_028-1.png"><img decoding="async" src="https://d9m.one/wp-content/uploads/2022/07/Pinball_028-1.png" alt="" class="wp-image-627" width="658" height="475" srcset="https://d9m.one/wp-content/uploads/2022/07/Pinball_028-1.png 877w, https://d9m.one/wp-content/uploads/2022/07/Pinball_028-1-300x217.png 300w, https://d9m.one/wp-content/uploads/2022/07/Pinball_028-1-768x554.png 768w" sizes="(max-width: 658px) 100vw, 658px" /></a><figcaption>【フリッパー割り当て】GameManagerの参照にフリッパーを割り当てる</figcaption></figure>



<ol class="wp-block-list"><li>ヒエラルキーの「Ball」をクリック</li><li>ヒエラルキーの「FlipperL」をインスペクターの「GameManager＞FlipperL」にドラッグ＆ドロップ</li><li>ヒエラルキーの「FlipperR」をインスペクターの「GameManager＞FlipperR」にドラッグ＆ドロップ</li><li>CTRLキーを押しながらSキーを押す</li></ol>



<h4 class="wp-block-heading"><span id="toc38">▷フリッパー制御確認</span></h4>



<p>マウスクリックでフリッパーを操作できることを確認します。</p>



<figure class="wp-block-image size-full is-resized"><a href="https://d9m.one/wp-content/uploads/2022/07/Pinball_029-1.png"><img decoding="async" src="https://d9m.one/wp-content/uploads/2022/07/Pinball_029-1.png" alt="" class="wp-image-628" width="658" height="475" srcset="https://d9m.one/wp-content/uploads/2022/07/Pinball_029-1.png 877w, https://d9m.one/wp-content/uploads/2022/07/Pinball_029-1-300x217.png 300w, https://d9m.one/wp-content/uploads/2022/07/Pinball_029-1-768x554.png 768w" sizes="(max-width: 658px) 100vw, 658px" /></a><figcaption>【フリッパー制御確認】マウスクリックでフリッパーを操作できることを確認</figcaption></figure>



<ol class="wp-block-list"><li>エディタ上中央の「▶」をクリック</li><li>ゲームビュー上でマウス左ボタンをクリック</li><li>左のフリッパーが動く事を確認</li><li>ゲームビュー上でマウス右ボタンをクリック</li><li>右のフリッパーが動く事を確認</li><li>エディタ上中央の「▶」をクリック</li></ol>



<h3 class="has-background has-medium-font-size wp-block-heading" style="background-color:#e5f7fd"><span id="toc39">●オブジェクト制御</span></h3>



<div style="height:16px" aria-hidden="true" class="wp-block-spacer"></div>



<h4 class="wp-block-heading"><span id="toc40">▷ターゲット設定</span></h4>



<p>ターゲットをトリガーにし、タグ「Target」を作成して割り当てます。</p>



<figure class="wp-block-image size-full is-resized"><a href="https://d9m.one/wp-content/uploads/2022/07/Pinball_030.png"><img decoding="async" src="https://d9m.one/wp-content/uploads/2022/07/Pinball_030.png" alt="" class="wp-image-626" width="658" height="475" srcset="https://d9m.one/wp-content/uploads/2022/07/Pinball_030.png 877w, https://d9m.one/wp-content/uploads/2022/07/Pinball_030-300x217.png 300w, https://d9m.one/wp-content/uploads/2022/07/Pinball_030-768x554.png 768w" sizes="(max-width: 658px) 100vw, 658px" /></a><figcaption>【ターゲット設定】ターゲットをトリガーにし、タグ「Target」を作成して割り当てる</figcaption></figure>



<ol class="wp-block-list"><li>プロジェクトの「Assets＞Prefabs＞Target」をダブルクリック</li><li>インスペクターの「Box Collider＞トリガーにする」をチェック</li><li>ヒエラルキーの「Target」をクリック</li><li>インスペクターのドロップダウン「タグ」をクリックし、「タグを追加&#8230;」をクリック</li><li>インスペクターのタグ右下の「＋」をクリック</li><li>「Target」と入力し、ENTERキーを押す</li><li>ヒエラルキーの「Target」をクリック</li><li>インスペクターのドロップダウン「タグ」をクリックし、「Target」をクリック</li><li>ヒエラルキー左上の「＜」をクリック</li></ol>



<h4 class="wp-block-heading"><span id="toc41">▷ターゲット制御</span></h4>



<p>プロジェクトの「Scripts＞GameManager」をダブルクリックし、玉がターゲットに衝突したらターゲットが消えるようにスクリプトを記述します。</p>



<div class="hcb_wrap"><pre class="prism line-numbers lang-plain" data-file="GameManager.cs"><code>using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class GameManager : MonoBehaviour
{
    public GameObject plunger;
    public GameObject flipperL;
    public GameObject flipperR;

    float plungerY = 3.5f;
    float[] angle = {0, 0};

    // Start is called before the first frame update
    void Start()
    {

    }

    // Update is called once per frame
    void Update()
    {
        Vector3 pos = plunger.transform.position;
        if (Input.GetAxis(&quot;Jump&quot;) &lt;= 0)
        {
            plungerY = Mathf.Clamp(plungerY + 0.5f, -3.5f, 0);
            pos.y = plungerY;
        }
        if (Input.GetAxis(&quot;Jump&quot;) &gt; 0)
        {
            plungerY = Mathf.Clamp(plungerY - 1, -3.5f, 0);
            pos.y = plungerY;
        }
        Rigidbody rb = plunger.GetComponent&lt;Rigidbody&gt;();
        rb.MovePosition(pos);

        FlipAction(0);
        FlipAction(1);
    }

    void FlipAction(int button)
    {
        if (Input.GetMouseButton(button) == true)
        {
            angle[button] += 16;
        }
        else
        {
            angle[button] -= 16;
        }
        angle[button] = Mathf.Clamp(angle[button], -18, 30);

        GameObject flipper;
        if (button == 0)
        {
            flipper = flipperL;
        }
        else
        {
            flipper = flipperR;
        }
        Rigidbody rb = flipper.GetComponent&lt;Rigidbody&gt;();

        Vector3 rot = flipper.transform.rotation.eulerAngles;
        rot.z = angle[button];
        rb.MoveRotation(Quaternion.Euler(rot));
    }

    void OnTriggerEnter(Collider collider)
    {
        if (collider.gameObject.CompareTag(&quot;Target&quot;))
        {
            Destroy(collider.gameObject);
        }
    }
}</code></pre></div>



<h4 class="wp-block-heading"><span id="toc42">▷ターゲット制御確認</span></h4>



<p>玉がターゲットに衝突したらターゲットが消えることを確認します。</p>



<figure class="wp-block-image size-full is-resized"><a href="https://d9m.one/wp-content/uploads/2022/07/Pinball_031.png"><img decoding="async" src="https://d9m.one/wp-content/uploads/2022/07/Pinball_031.png" alt="" class="wp-image-629" width="658" height="475" srcset="https://d9m.one/wp-content/uploads/2022/07/Pinball_031.png 877w, https://d9m.one/wp-content/uploads/2022/07/Pinball_031-300x217.png 300w, https://d9m.one/wp-content/uploads/2022/07/Pinball_031-768x554.png 768w" sizes="(max-width: 658px) 100vw, 658px" /></a><figcaption>【ターゲット制御確認】玉がターゲットに衝突したらターゲットが消えることを確認</figcaption></figure>



<ol class="wp-block-list"><li>エディタ上中央の「▶」をクリック</li><li>玉をターゲットに衝突させる</li><li>ターゲットが消滅する事を確認</li><li>エディタ上中央の「▶」をクリック</li></ol>



<h4 class="wp-block-heading"><span id="toc43">▷バンパー物理設定</span></h4>



<p>バンパーにRigidbodyを割り当て、Is Kinematic(あり)、衝突判定(連続的かつ動的)とします。</p>



<figure class="wp-block-image size-full is-resized"><a href="https://d9m.one/wp-content/uploads/2022/07/Pinball_032.png"><img decoding="async" src="https://d9m.one/wp-content/uploads/2022/07/Pinball_032.png" alt="" class="wp-image-630" width="658" height="475" srcset="https://d9m.one/wp-content/uploads/2022/07/Pinball_032.png 877w, https://d9m.one/wp-content/uploads/2022/07/Pinball_032-300x217.png 300w, https://d9m.one/wp-content/uploads/2022/07/Pinball_032-768x554.png 768w" sizes="(max-width: 658px) 100vw, 658px" /></a><figcaption>【バンパー物理設定】バンパーにRigidbodyを割り当て、Is Kinematic(あり)、衝突判定(連続的かつ動的)とする</figcaption></figure>



<ol class="wp-block-list"><li>プロジェクトの「Assets＞Prefabs＞Bumper」をダブルクリック</li><li>インスペクターの「コンポーネントを追加」をクリックし、Physics＞Rigidbodyをクリック</li><li>インスペクターの「Rigidbody＞Is Kinematic」をチェック</li><li>インスペクターの「Rigidbody＞衝突判定」を(連続的かつ動的)に設定</li><li>ヒエラルキーの左上にある「＜」をクリック</li></ol>



<h4 class="wp-block-heading"><span id="toc44">▷バンパー認識</span></h4>



<p>タグ「Bumper」を作成し、バンパーに割り当てます。</p>



<figure class="wp-block-image size-full is-resized"><a href="https://d9m.one/wp-content/uploads/2022/07/Pinball_033.png"><img decoding="async" src="https://d9m.one/wp-content/uploads/2022/07/Pinball_033.png" alt="" class="wp-image-631" width="658" height="475" srcset="https://d9m.one/wp-content/uploads/2022/07/Pinball_033.png 877w, https://d9m.one/wp-content/uploads/2022/07/Pinball_033-300x217.png 300w, https://d9m.one/wp-content/uploads/2022/07/Pinball_033-768x554.png 768w" sizes="(max-width: 658px) 100vw, 658px" /></a><figcaption>【バンパー認識】タグ「Bumper」を作成し、バンパーに割り当てる</figcaption></figure>



<ol class="wp-block-list"><li>プロジェクトの「Assets＞Prefabs＞Bumper」をダブルクリック</li><li>ヒエラルキーの「Bumper」をクリック</li><li>インスペクターのドロップダウン「タグ」をクリックし、「タグを追加&#8230;」をクリック</li><li>インスペクターのタグ右下の「＋」をクリック</li><li>「Bumper」と入力し、ENTERキーを押す</li><li>ヒエラルキーの「Bumper」をクリック</li><li>インスペクターのドロップダウン「タグ」をクリックし、「Bumper」をクリック</li><li>ヒエラルキー左上の「＜」をクリック</li></ol>



<h4 class="wp-block-heading"><span id="toc45">▷バンパー制御</span></h4>



<p>プロジェクトの「Assets＞Scripts＞GameManager」をダブルクリックし、玉がバンパーに衝突したら弾かれるようにスクリプトを記述します。</p>



<div class="hcb_wrap"><pre class="prism line-numbers lang-plain" data-file="GameManager.cs"><code>using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class GameManager : MonoBehaviour
{
    public GameObject plunger;
    public GameObject flipperL;
    public GameObject flipperR;

    float plungerY = 3.5f;
    float[] angle = {0, 0};

    // Start is called before the first frame update
    void Start()
    {

    }

    // Update is called once per frame
    void Update()
    {
        Vector3 pos = plunger.transform.position;
        if (Input.GetAxis(&quot;Jump&quot;) &lt;= 0)
        {
            plungerY = Mathf.Clamp(plungerY + 0.5f, -3.5f, 0);
            pos.y = plungerY;
        }
        if (Input.GetAxis(&quot;Jump&quot;) &gt; 0)
        {
            plungerY = Mathf.Clamp(plungerY - 1, -3.5f, 0);
            pos.y = plungerY;
        }
        Rigidbody rb = plunger.GetComponent&lt;Rigidbody&gt;();
        rb.MovePosition(pos);

        FlipAction(0);
        FlipAction(1);
    }

    void FlipAction(int button)
    {
        if (Input.GetMouseButton(button) == true)
        {
            angle[button] += 16;
        }
        else
        {
            angle[button] -= 16;
        }
        angle[button] = Mathf.Clamp(angle[button], -18, 30);

        GameObject flipper;
        if (button == 0)
        {
            flipper = flipperL;
        }
        else
        {
            flipper = flipperR;
        }
        Rigidbody rb = flipper.GetComponent&lt;Rigidbody&gt;();

        Vector3 rot = flipper.transform.rotation.eulerAngles;
        rot.z = angle[button];
        rb.MoveRotation(Quaternion.Euler(rot));
    }

    void OnTriggerEnter(Collider collider)
    {
        if (collider.gameObject.CompareTag(&quot;Target&quot;))
        {
            Destroy(collider.gameObject);
        }
    }

    void OnCollisionEnter(Collision collision)
    {
        if (collision.gameObject.CompareTag(&quot;Bumper&quot;))
        {
            Vector3 dir = transform.position - collision.transform.position;
            Rigidbody rb = GetComponent&lt;Rigidbody&gt;();
            rb.AddForce(dir * 30, ForceMode.Impulse);
        }
    }
}</code></pre></div>



<h4 class="wp-block-heading"><span id="toc46">▷バンパー制御確認</span></h4>



<p>玉がバンパーに衝突したら弾かれる事を確認します。</p>



<figure class="wp-block-image size-full is-resized"><a href="https://d9m.one/wp-content/uploads/2022/07/Pinball_034.png"><img decoding="async" src="https://d9m.one/wp-content/uploads/2022/07/Pinball_034.png" alt="" class="wp-image-632" width="658" height="475" srcset="https://d9m.one/wp-content/uploads/2022/07/Pinball_034.png 877w, https://d9m.one/wp-content/uploads/2022/07/Pinball_034-300x217.png 300w, https://d9m.one/wp-content/uploads/2022/07/Pinball_034-768x554.png 768w" sizes="(max-width: 658px) 100vw, 658px" /></a><figcaption>【バンパー制御確認】玉がバンパーに衝突したら弾かれる事を確認</figcaption></figure>



<ol class="wp-block-list"><li>エディタ上中央の「▶」をクリック</li><li>バンパーに玉を衝突させる</li><li>玉が弾かれる事を確認</li><li>エディタ上中央の「▶」をクリック</li></ol>



<h3 class="has-background has-medium-font-size wp-block-heading" style="background-color:#e5f7fd"><span id="toc47">●ゲーム制御</span></h3>



<div style="height:16px" aria-hidden="true" class="wp-block-spacer"></div>



<h4 class="wp-block-heading"><span id="toc48">▷ミスエリア認識</span></h4>



<p>ミスエリアにタグ「Finish」を割り当てます。</p>



<figure class="wp-block-image size-full is-resized"><a href="https://d9m.one/wp-content/uploads/2022/07/Pinball_035.png"><img decoding="async" src="https://d9m.one/wp-content/uploads/2022/07/Pinball_035.png" alt="" class="wp-image-633" width="658" height="475" srcset="https://d9m.one/wp-content/uploads/2022/07/Pinball_035.png 877w, https://d9m.one/wp-content/uploads/2022/07/Pinball_035-300x217.png 300w, https://d9m.one/wp-content/uploads/2022/07/Pinball_035-768x554.png 768w" sizes="(max-width: 658px) 100vw, 658px" /></a><figcaption>【ミスエリア認識】ミスエリアにタグ「Finish」を割り当てる</figcaption></figure>



<ol class="wp-block-list"><li>ヒエラルキーの「WallMiss」をクリック</li><li>インスペクターのドロップダウン「タグ」をクリックし、「Finish」をクリック</li><li>CTRLキーを押しながらSキーを押す</li></ol>



<h4 class="wp-block-heading"><span id="toc49">▷リスタート制御</span></h4>



<p>プロジェクトの「Assets＞Scripts＞GameManager」をダブルクリックし、玉がミスエリアに衝突したらリスタートするスクリプトを記述します。</p>



<div class="hcb_wrap"><pre class="prism line-numbers lang-plain" data-file="GameManager.cs"><code>using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;

public class GameManager : MonoBehaviour
{
    public GameObject plunger;
    public GameObject flipperL;
    public GameObject flipperR;

    float plungerY = 3.5f;
    float[] angle = {0, 0};

    // Start is called before the first frame update
    void Start()
    {

    }

    // Update is called once per frame
    void Update()
    {
        Vector3 pos = plunger.transform.position;
        if (Input.GetAxis(&quot;Jump&quot;) &lt;= 0)
        {
            plungerY = Mathf.Clamp(plungerY + 0.5f, -3.5f, 0);
            pos.y = plungerY;
        }
        if (Input.GetAxis(&quot;Jump&quot;) &gt; 0)
        {
            plungerY = Mathf.Clamp(plungerY - 1, -3.5f, 0);
            pos.y = plungerY;
        }
        Rigidbody rb = plunger.GetComponent&lt;Rigidbody&gt;();
        rb.MovePosition(pos);

        FlipAction(0);
        FlipAction(1);
    }

    void FlipAction(int button)
    {
        if (Input.GetMouseButton(button) == true)
        {
            angle[button] += 16;
        }
        else
        {
            angle[button] -= 16;
        }
        angle[button] = Mathf.Clamp(angle[button], -18, 30);

        GameObject flipper;
        if (button == 0)
        {
            flipper = flipperL;
        }
        else
        {
            flipper = flipperR;
        }
        Rigidbody rb = flipper.GetComponent&lt;Rigidbody&gt;();

        Vector3 rot = flipper.transform.rotation.eulerAngles;
        rot.z = angle[button];
        rb.MoveRotation(Quaternion.Euler(rot));
    }

    void OnTriggerEnter(Collider collider)
    {
        if (collider.gameObject.CompareTag(&quot;Target&quot;))
        {
            Destroy(collider.gameObject);
        }
    }

    void OnCollisionEnter(Collision collision)
    {
        if (collision.gameObject.CompareTag(&quot;Bumper&quot;))
        {
            Vector3 dir = transform.position - collision.transform.position;
            Rigidbody rb = GetComponent&lt;Rigidbody&gt;();
            rb.AddForce(dir * 30, ForceMode.Impulse);
        }
        if (collision.gameObject.CompareTag(&quot;Finish&quot;))
        {
            SceneManager.LoadScene(SceneManager.GetActiveScene().name);
        }
    }
}</code></pre></div>



<h4 class="wp-block-heading"><span id="toc50">▷リスタート確認</span></h4>



<p>玉がミスエリアに衝突したらゲームがやり直しになる事を確認します。</p>



<figure class="wp-block-image size-full is-resized"><a href="https://d9m.one/wp-content/uploads/2022/07/Pinball_036.png"><img decoding="async" src="https://d9m.one/wp-content/uploads/2022/07/Pinball_036.png" alt="" class="wp-image-634" width="658" height="475" srcset="https://d9m.one/wp-content/uploads/2022/07/Pinball_036.png 877w, https://d9m.one/wp-content/uploads/2022/07/Pinball_036-300x217.png 300w, https://d9m.one/wp-content/uploads/2022/07/Pinball_036-768x554.png 768w" sizes="(max-width: 658px) 100vw, 658px" /></a><figcaption>【リスタート確認】玉がミスエリアに衝突したらゲームがやり直しになる事を確認</figcaption></figure>



<ol class="wp-block-list"><li>エディタ上中央の「▶」をクリック</li><li>ミスエリアに玉を衝突させる</li><li>ゲームがやり直しになる事を確認</li><li>エディタ上中央の「▶」をクリック</li></ol>



<h4 class="wp-block-heading"><span id="toc51">▷クリアUI作成</span></h4>



<p>クリア用のUIテキストを非アクティブで配置します。</p>



<figure class="wp-block-image size-full is-resized"><a href="https://d9m.one/wp-content/uploads/2022/07/Pinball_037.png"><img decoding="async" src="https://d9m.one/wp-content/uploads/2022/07/Pinball_037.png" alt="" class="wp-image-635" width="658" height="475" srcset="https://d9m.one/wp-content/uploads/2022/07/Pinball_037.png 877w, https://d9m.one/wp-content/uploads/2022/07/Pinball_037-300x217.png 300w, https://d9m.one/wp-content/uploads/2022/07/Pinball_037-768x554.png 768w" sizes="(max-width: 658px) 100vw, 658px" /></a><figcaption>【クリアUI作成】クリア用のUIテキストを非アクティブで配置する</figcaption></figure>



<ol class="wp-block-list"><li>ヒエラルキー左上の「＋」をクリックし、「UI＞テキスト &#8211; TextMeshPro」をクリック</li><li>TMP Importerの「Import TMP Essentials」をクリック</li><li>TMP Importerを閉じる</li><li>ヒエラルキーの「Text (TMP)」をクリック</li><li>F2キーを押して「TextClear」と入力し、ENTERキーを押す</li><li>インスペクターを以下のように設定</li><li>・RectTransform左上のアイコン「アンカープリセット」をクリックし、右下の「stretch &#8211; stretch」をダブルクリック</li><li>・RectTransformの「上下左右」を(0, 0, 0, 0)に設定</li><li>・TextMeshProの「Text Input」にあるテキスト入力を「Clear!」に設定</li><li>・TextMeshProの「Main Settings&gt;Font Style」にある「B」をオンにする</li><li>・TextMeshProの「Main Settings&gt;Auto Size」にチェックを入れる</li><li>・TextMeshProの「Main Settings&gt;Vertex Color」右にあるカラーバーをクリックし、色ダイアログの16進数を「FFFF00」に設定</li><li>・色ダイアログの右上にある「×」をクリック</li><li>・TextMeshProの「Main Settings&gt;Alignment」にある「Center、Middle」をオンにする</li><li>・マテリアル設定にある「Outline」にチェックを入れる</li><li>・マテリアル設定にある「Outline&gt;Thickness」を(0.2)に設定</li><li>・マテリアル設定にある「Outline&gt;Color」にあるカラーバーをクリックし、HDRカラーのRを「255」に設定</li><li>・HDRカラーの右上にある「×」をクリック</li><li>インスペクター左上のチェックを外す</li><li>CTRLキーを押しながらSキーを押す</li></ol>



<h4 class="wp-block-heading"><span id="toc52">▷クリア制御</span></h4>



<p>プロジェクトの「Assets＞Scripts＞GameManager」をダブルクリックし、ターゲットを全て取得したらクリアUIを表示するスクリプトを記述します。</p>



<div class="hcb_wrap"><pre class="prism line-numbers lang-plain" data-file="GameManager.cs"><code>using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;

public class GameManager : MonoBehaviour
{
    public GameObject plunger;
    public GameObject flipperL;
    public GameObject flipperR;
    public GameObject uiClear;

    float plungerY = 3.5f;
    float[] angle = {0, 0};

    // Start is called before the first frame update
    void Start()
    {

    }

    // Update is called once per frame
    void Update()
    {
        GameObject[] targets = GameObject.FindGameObjectsWithTag(&quot;Target&quot;);
        if (targets.Length == 0)
        {
            uiClear.SetActive(true);
            Destroy(gameObject);
            return;
        }

        Vector3 pos = plunger.transform.position;
        if (Input.GetAxis(&quot;Jump&quot;) &lt;= 0)
        {
            plungerY = Mathf.Clamp(plungerY + 0.5f, -3.5f, 0);
            pos.y = plungerY;
        }
        if (Input.GetAxis(&quot;Jump&quot;) &gt; 0)
        {
            plungerY = Mathf.Clamp(plungerY - 1, -3.5f, 0);
            pos.y = plungerY;
        }
        Rigidbody rb = plunger.GetComponent&lt;Rigidbody&gt;();
        rb.MovePosition(pos);

        FlipAction(0);
        FlipAction(1);
    }

    void FlipAction(int button)
    {
        if (Input.GetMouseButton(button) == true)
        {
            angle[button] += 16;
        }
        else
        {
            angle[button] -= 16;
        }
        angle[button] = Mathf.Clamp(angle[button], -18, 30);

        GameObject flipper;
        if (button == 0)
        {
            flipper = flipperL;
        }
        else
        {
            flipper = flipperR;
        }
        Rigidbody rb = flipper.GetComponent&lt;Rigidbody&gt;();

        Vector3 rot = flipper.transform.rotation.eulerAngles;
        rot.z = angle[button];
        rb.MoveRotation(Quaternion.Euler(rot));
    }

    void OnTriggerEnter(Collider collider)
    {
        if (collider.gameObject.CompareTag(&quot;Target&quot;))
        {
            Destroy(collider.gameObject);
        }
    }

    void OnCollisionEnter(Collision collision)
    {
        if (collision.gameObject.CompareTag(&quot;Bumper&quot;))
        {
            Vector3 dir = transform.position - collision.transform.position;
            Rigidbody rb = GetComponent&lt;Rigidbody&gt;();
            rb.AddForce(dir * 30, ForceMode.Impulse);
        }
        if (collision.gameObject.CompareTag(&quot;Finish&quot;))
        {
            SceneManager.LoadScene(SceneManager.GetActiveScene().name);
        }
    }
}</code></pre></div>



<h4 class="wp-block-heading"><span id="toc53">▷クリアUI割り当て</span></h4>



<p>クリア用UIテキストをGameManagerの参照に割り当てます。</p>



<figure class="wp-block-image size-full is-resized"><a href="https://d9m.one/wp-content/uploads/2022/07/Pinball_038.png"><img decoding="async" src="https://d9m.one/wp-content/uploads/2022/07/Pinball_038.png" alt="" class="wp-image-636" width="658" height="475" srcset="https://d9m.one/wp-content/uploads/2022/07/Pinball_038.png 877w, https://d9m.one/wp-content/uploads/2022/07/Pinball_038-300x217.png 300w, https://d9m.one/wp-content/uploads/2022/07/Pinball_038-768x554.png 768w" sizes="(max-width: 658px) 100vw, 658px" /></a><figcaption>【クリアUI割り当て】クリア用UIテキストをGameManagerの参照に割り当てる</figcaption></figure>



<ol class="wp-block-list"><li>ヒエラルキーの「Ball」をクリック</li><li>ヒエラルキーの「Canvas＞TextClear」をインスペクターの「Ui Clear」にドラッグ＆ドロップ</li><li>CTRLキーを押しながらSキーを押す</li></ol>



<h4 class="wp-block-heading"><span id="toc54">▷クリア確認</span></h4>



<p>全てのターゲットを取得したら玉が消えてクリアが表示される事を確認します。</p>



<figure class="wp-block-image size-full is-resized"><a href="https://d9m.one/wp-content/uploads/2022/07/Pinball_039.png"><img decoding="async" src="https://d9m.one/wp-content/uploads/2022/07/Pinball_039.png" alt="" class="wp-image-637" width="658" height="475" srcset="https://d9m.one/wp-content/uploads/2022/07/Pinball_039.png 877w, https://d9m.one/wp-content/uploads/2022/07/Pinball_039-300x217.png 300w, https://d9m.one/wp-content/uploads/2022/07/Pinball_039-768x554.png 768w" sizes="(max-width: 658px) 100vw, 658px" /></a><figcaption>【クリア確認】全てのターゲットを取得したら玉が消えてクリアが表示される事を確認</figcaption></figure>



<ol class="wp-block-list"><li>エディタ上中央の「▶」をクリック</li><li>全てのターゲットを取得する</li><li>玉が消え、クリアが表示される事を確認</li><li>エディタ上中央の「▶」をクリック</li></ol>



<div style="height:16px" aria-hidden="true" class="wp-block-spacer"></div>



<p class="has-text-align-center has-x-large-font-size">完成！</p>
<p>投稿 <a href="https://d9m.one/proc_pinball_full/">【基本操作】ピンボール～完全手順【アクション】</a> は <a href="https://d9m.one">だくまたゲーム制作ブログ</a> に最初に表示されました。</p>
]]></content:encoded>
					
					<wfw:commentRss>https://d9m.one/proc_pinball_full/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>【基本操作】的当てゲーム～２／２　ゲーム制御【アクション】</title>
		<link>https://d9m.one/proc_matoate2/</link>
					<comments>https://d9m.one/proc_matoate2/#respond</comments>
		
		<dc:creator><![CDATA[だくまた]]></dc:creator>
		<pubDate>Thu, 30 Jun 2022 14:35:02 +0000</pubDate>
				<category><![CDATA[Unity]]></category>
		<category><![CDATA[基本操作]]></category>
		<category><![CDATA[チュートリアル]]></category>
		<guid isPermaLink="false">https://d9m.one/?p=1023</guid>

					<description><![CDATA[<p>●銅結果UI作成 ▷結果テキスト準備 UIテキストを作成し、TextMeshProをインポートします。 ヒエラルキー左上の「＋」をクリックし、「UI＞テキスト &#8211; TextMeshPro」をクリック TMP  [&#8230;]</p>
<p>投稿 <a href="https://d9m.one/proc_matoate2/">【基本操作】的当てゲーム～２／２　ゲーム制御【アクション】</a> は <a href="https://d9m.one">だくまたゲーム制作ブログ</a> に最初に表示されました。</p>
]]></description>
										<content:encoded><![CDATA[
<div style="height:16px" aria-hidden="true" class="wp-block-spacer"></div>



<h3 class="has-background has-medium-font-size wp-block-heading" style="background-color:#e5f7fd"><span id="toc1">●銅結果UI作成</span></h3>



<div style="height:16px" aria-hidden="true" class="wp-block-spacer"></div>



<div class="wp-block-group is-layout-flow wp-block-group-is-layout-flow">
<h4 class="wp-block-heading"><span id="toc2">▷結果テキスト準備</span></h4>



<p>UIテキストを作成し、TextMeshProをインポートします。</p>



<figure class="wp-block-image size-full is-resized"><a href="https://d9m.one/wp-content/uploads/2022/06/Matoate_016.png"><img decoding="async" src="https://d9m.one/wp-content/uploads/2022/06/Matoate_016.png" alt="" class="wp-image-532" width="658" height="475" srcset="https://d9m.one/wp-content/uploads/2022/06/Matoate_016.png 877w, https://d9m.one/wp-content/uploads/2022/06/Matoate_016-300x217.png 300w, https://d9m.one/wp-content/uploads/2022/06/Matoate_016-768x554.png 768w" sizes="(max-width: 658px) 100vw, 658px" /></a><figcaption>【結果テキスト準備】UIテキストを作成し、TextMeshProをインポート</figcaption></figure>



<ol class="wp-block-list"><li>ヒエラルキー左上の「＋」をクリックし、「UI＞テキスト &#8211; TextMeshPro」をクリック</li><li>TMP Importerの「Import TMP Essentials」をクリック</li><li>TMP Importerを閉じる</li><li>ヒエラルキーの「Text (TMP)」をクリック</li><li>F2キーを押して「TextCopper」と入力し、ENTERキーを押す</li><li>CTRLキーを押しながらSキーを押す</li></ol>



<h4 class="wp-block-heading"><span id="toc3">▷結果テキスト配置</span></h4>



<p>RectTransformを「stretch &#8211; stretch」のマージン無しに設定します。</p>



<figure class="wp-block-image size-full is-resized"><a href="https://d9m.one/wp-content/uploads/2022/06/Matoate_017.png"><img decoding="async" src="https://d9m.one/wp-content/uploads/2022/06/Matoate_017.png" alt="" class="wp-image-533" width="658" height="475" srcset="https://d9m.one/wp-content/uploads/2022/06/Matoate_017.png 877w, https://d9m.one/wp-content/uploads/2022/06/Matoate_017-300x217.png 300w, https://d9m.one/wp-content/uploads/2022/06/Matoate_017-768x554.png 768w" sizes="(max-width: 658px) 100vw, 658px" /></a><figcaption>【結果テキスト配置】RectTransformを「stretch &#8211; stretch」のマージン無しに設定</figcaption></figure>



<ol class="wp-block-list"><li>インスペクターのRectTransformを以下のように設定</li><li>・左上のアイコン「アンカープリセット」をクリックし、右下の「stretch &#8211; stretch」をダブルクリック</li><li>・「上下左右」を(0, 0, 0, 0)に設定</li><li>CTRLキーを押しながらSキーを押す</li></ol>



<h4 class="wp-block-heading"><span id="toc4">▷結果テキスト表示文字設定</span></h4>



<p>表示文字を「Copper!」とし、太字/AudoSize/金色/中央表示に設定します。</p>



<figure class="wp-block-image size-full is-resized"><a href="https://d9m.one/wp-content/uploads/2022/06/Matoate_018.png"><img decoding="async" src="https://d9m.one/wp-content/uploads/2022/06/Matoate_018.png" alt="" class="wp-image-534" width="658" height="475" srcset="https://d9m.one/wp-content/uploads/2022/06/Matoate_018.png 877w, https://d9m.one/wp-content/uploads/2022/06/Matoate_018-300x217.png 300w, https://d9m.one/wp-content/uploads/2022/06/Matoate_018-768x554.png 768w" sizes="(max-width: 658px) 100vw, 658px" /></a><figcaption>【結果テキスト表示文字設定】表示文字を「Copper!」とし、太字/AudoSize/金色/中央表示に設定</figcaption></figure>



<ol class="wp-block-list"><li>インスペクターのTextMeshProを以下のように設定</li><li>・「Text Input&gt;テキスト入力」を「Copper!」に設定</li><li>・「Main Settings&gt;Font Style」の「B」をオンにする</li><li>・「Main Settings&gt;Auto Size」にチェックを入れる</li><li>・「Main Settings&gt;VertexColor」のカラーバーをクリックし、色ダイアログの16進数を「DA744B」に設定</li><li>・色ダイアログの右上にある「×」をクリック</li><li>・「Main Settings&gt;Alignment」の「Center、Middle」をオンにする</li><li>CTRLキーを押しながらSキーを押す</li></ol>



<h4 class="wp-block-heading"><span id="toc5">▷結果テキストマテリアル設定</span></h4>



<p>マテリアルのOutlineを細めのねずみ色に設定します。</p>



<figure class="wp-block-image size-full is-resized"><a href="https://d9m.one/wp-content/uploads/2022/06/Matoate_019.png"><img decoding="async" src="https://d9m.one/wp-content/uploads/2022/06/Matoate_019.png" alt="" class="wp-image-551" width="658" height="475" srcset="https://d9m.one/wp-content/uploads/2022/06/Matoate_019.png 877w, https://d9m.one/wp-content/uploads/2022/06/Matoate_019-300x217.png 300w, https://d9m.one/wp-content/uploads/2022/06/Matoate_019-768x554.png 768w" sizes="(max-width: 658px) 100vw, 658px" /></a><figcaption>【結果テキストマテリアル設定】マテリアルのOutlineを細めのねずみ色に設定</figcaption></figure>



<ol class="wp-block-list"><li>インスペクターのマテリアルを以下のように設定（Extra Settingsの下）</li><li>・Outlineにチェックを入れる</li><li>・OutlineのThicknessを(0.2)に設定</li><li>・OutlineのColorにあるカラーバーをクリックし、Rを(64)、Gを(64)、Bを(64)に設定</li></ol>
</div>



<div style="height:16px" aria-hidden="true" class="wp-block-spacer"></div>



<h3 class="has-background has-medium-font-size wp-block-heading" style="background-color:#e5f7fd"><span id="toc6">●銅結果UI表示</span></h3>



<div style="height:16px" aria-hidden="true" class="wp-block-spacer"></div>



<div class="wp-block-group is-layout-flow wp-block-group-is-layout-flow">
<h4 class="wp-block-heading"><span id="toc7">▷結果テキスト制御準備</span></h4>



<p>スクリプトを作成して銅のマトに割り当て、結果テキストを無効状態に設定します。</p>



<figure class="wp-block-image size-full is-resized"><a href="https://d9m.one/wp-content/uploads/2022/06/Matoate_020.png"><img decoding="async" src="https://d9m.one/wp-content/uploads/2022/06/Matoate_020.png" alt="" class="wp-image-536" width="658" height="475" srcset="https://d9m.one/wp-content/uploads/2022/06/Matoate_020.png 877w, https://d9m.one/wp-content/uploads/2022/06/Matoate_020-300x217.png 300w, https://d9m.one/wp-content/uploads/2022/06/Matoate_020-768x554.png 768w" sizes="(max-width: 658px) 100vw, 658px" /></a><figcaption>【結果テキスト制御準備】スクリプトを作成して銅のマトに割り当て、結果テキストを無効状態に設定</figcaption></figure>



<ol class="wp-block-list"><li>プロジェクトの「Assets」を右クリックし、「作成＞C# スクリプト」をクリック</li><li>「Result」と入力し、ENTERキーを押す</li><li>プロジェクトの「Assets&gt;Result」をヒエラルキーの「Copper」にドラッグ＆ドロップ</li><li>ヒエラルキーの「TextCopper」をクリック</li><li>インスペクターのオブジェクト名左にあるチェックを外す</li><li>CTRLキーを押しながらSキーを押す</li></ol>



<h4 class="wp-block-heading"><span id="toc8">▷結果テキスト制御</span></h4>



<p>球が衝突したら球が物理影響を受けないようにし、結果テキストを表示するように設定します。</p>



<figure class="wp-block-image size-full is-resized"><a href="https://d9m.one/wp-content/uploads/2022/06/Matoate_021.png"><img decoding="async" src="https://d9m.one/wp-content/uploads/2022/06/Matoate_021.png" alt="" class="wp-image-537" width="658" height="475" srcset="https://d9m.one/wp-content/uploads/2022/06/Matoate_021.png 877w, https://d9m.one/wp-content/uploads/2022/06/Matoate_021-300x217.png 300w, https://d9m.one/wp-content/uploads/2022/06/Matoate_021-768x554.png 768w" sizes="(max-width: 658px) 100vw, 658px" /></a><figcaption>【結果テキスト制御】球が衝突したら球が物理影響を受けないようにし、結果テキストを表示するように設定</figcaption></figure>



<ol class="wp-block-list"><li>プロジェクトの「Assets&gt;Result」をダブルクリック</li><li>Start関数のコメントより上に「Unity側で編集可能なゲームオブジェクト型の変数」を定義</li><li>Update関数の下に「オブジェクトと衝突した時に呼ばれる関数」を定義</li><li>「オブジェクトと衝突した時に呼ばれる関数」に以下の処理を記述</li><li>・UIテキストを有効化</li><li>・衝突オブジェクトが物理影響を受けないように設定</li><li>Unityエディタのタイトルをクリック</li><li>ヒエラルキーの「Copper」をクリック</li><li>ヒエラルキーの「Canvas&gt;TextCopper」をインスペクターの「Result&gt;Ui Text」右側の枠にドラッグ＆ドロップ</li><li>CTRLキーを押しながらSキーを押す</li><li>エディタ上中央の「▶」をクリック</li><li>球を銅のマトに当てたら「Copper!」と表示されることを確認</li><li>球を銅のマトに当てたら球の動きが止まることを確認</li><li>エディタ上中央の「▶」をクリック</li></ol>



<h4 class="wp-block-heading"><span id="toc9">▷結果テキスト制御</span></h4>



<p>スクリプトの記述例です。</p>



<div class="hcb_wrap"><pre class="prism line-numbers lang-csharp" data-file="Result.cs" data-lang="C#"><code>using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Result : MonoBehaviour
{
    // Unity側で編集可能なゲームオブジェクト型の変数を定義
    public GameObject uiText;

    // Start is called before the first frame update
    void Start()
    {
        
    }

    // Update is called once per frame
    void Update()
    {
        
    }

    // オブジェクトと衝突した時に呼ばれる関数を定義
    void OnCollisionEnter(Collision collision)
    {
        // UIテキストを有効化
        uiText.SetActive(true);
        // 衝突オブジェクトが物理影響を受けないように設定
        collision.gameObject.GetComponent&lt;Rigidbody&gt;().isKinematic = true;
    }
}</code></pre></div>



<h4 class="wp-block-heading"><span id="toc10">▷銀結果作成</span></h4>



<p>銅結果UIを複製し、表示文字を「Silver!」、文字色を銀色に設定します。</p>



<figure class="wp-block-image size-full is-resized"><a href="https://d9m.one/wp-content/uploads/2022/06/Matoate_022.png"><img decoding="async" src="https://d9m.one/wp-content/uploads/2022/06/Matoate_022.png" alt="" class="wp-image-538" width="658" height="475" srcset="https://d9m.one/wp-content/uploads/2022/06/Matoate_022.png 877w, https://d9m.one/wp-content/uploads/2022/06/Matoate_022-300x217.png 300w, https://d9m.one/wp-content/uploads/2022/06/Matoate_022-768x554.png 768w" sizes="(max-width: 658px) 100vw, 658px" /></a><figcaption>【銀結果作成】銅結果UIを複製し、表示文字を「Silver!」、文字色を銀色に設定</figcaption></figure>



<ol class="wp-block-list"><li>ヒエラルキーの「Canvas&gt;TextCopper」をクリック</li><li>CTRLキーを押しながらDキーを押す</li><li>F2キーを押して「TextSilver」と入力し、ENTERキーを押す</li><li>インスペクターの「TextMeshPro&gt;TextInput」下にあるテキスト入力に「Silver!」と入力</li><li>インスペクターの「TextMeshPro&gt;Vertex Color」右にあるカラーバーをクリック、色ダイアログの16進数に「C0C0C0」と入力</li><li>色ダイアログの右上にある「×」をクリック</li><li>CTRLキーを押しながらSキーを押す</li></ol>



<h4 class="wp-block-heading"><span id="toc11">▷銀結果制御</span></h4>



<p>銀のマトに結果テキスト表示スクリプトを割り当て、銀結果UIを表示対象に設定します。</p>



<figure class="wp-block-image size-full is-resized"><a href="https://d9m.one/wp-content/uploads/2022/06/Matoate_023.png"><img decoding="async" src="https://d9m.one/wp-content/uploads/2022/06/Matoate_023.png" alt="" class="wp-image-539" width="658" height="475" srcset="https://d9m.one/wp-content/uploads/2022/06/Matoate_023.png 877w, https://d9m.one/wp-content/uploads/2022/06/Matoate_023-300x217.png 300w, https://d9m.one/wp-content/uploads/2022/06/Matoate_023-768x554.png 768w" sizes="(max-width: 658px) 100vw, 658px" /></a><figcaption>【銀結果制御】銀のマトに結果テキスト表示スクリプトを割り当て、銀結果UIを表示対象に設定</figcaption></figure>



<ol class="wp-block-list"><li>プロジェクトの「Assets&gt;Result」をヒエラルキーの「Silver」にドラッグ＆ドロップ</li><li>ヒエラルキーの「Silver」をクリック</li><li>ヒエラルキーの「Canvas&gt;TextSilver」をインスペクターの「Result&gt;Ui Text」にドラッグ＆ドロップ</li><li>CTRLキーを押しながらSキーを押す</li><li>エディタ上中央の「▶」をクリック</li><li>球を銀のマトに当てたら「Silver!」と表示されることを確認</li><li>球を銀のマトに当てたら球の動きが止まることを確認</li><li>エディタ上中央の「▶」をクリック</li></ol>



<h4 class="wp-block-heading"><span id="toc12">▷金結果作成</span></h4>



<p>銀結果UIを複製し、表示文字を「Gold!」、文字色を金色に設定します。</p>



<figure class="wp-block-image size-full is-resized"><a href="https://d9m.one/wp-content/uploads/2022/06/Matoate_024.png"><img decoding="async" src="https://d9m.one/wp-content/uploads/2022/06/Matoate_024.png" alt="" class="wp-image-540" width="658" height="475" srcset="https://d9m.one/wp-content/uploads/2022/06/Matoate_024.png 877w, https://d9m.one/wp-content/uploads/2022/06/Matoate_024-300x217.png 300w, https://d9m.one/wp-content/uploads/2022/06/Matoate_024-768x554.png 768w" sizes="(max-width: 658px) 100vw, 658px" /></a><figcaption>【金結果作成】銀結果UIを複製し、表示文字を「Gold!」、文字色を金色に設定</figcaption></figure>



<ol class="wp-block-list"><li>ヒエラルキーの「Canvas&gt;TextSilver」をクリック</li><li>CTRLキーを押しながらDキーを押す</li><li>F2キーを押して「TextGold」と入力し、ENTERキーを押す</li><li>インスペクターの「TextMeshPro&gt;TextInput」下にあるテキスト入力に「Gold!」と入力</li><li>インスペクターの「TextMeshPro&gt;Vertex Color」右にあるカラーバーをクリック、色ダイアログの16進数に「FFD700」と入力</li><li>色ダイアログの右上にある「×」をクリック</li><li>CTRLキーを押しながらSキーを押す</li></ol>



<h4 class="wp-block-heading"><span id="toc13">▷金結果制御</span></h4>



<p>金のマトに結果テキスト表示スクリプトを割り当て、金結果UIを表示対象に設定します。</p>



<figure class="wp-block-image size-full is-resized"><a href="https://d9m.one/wp-content/uploads/2022/06/Matoate_025.png"><img decoding="async" src="https://d9m.one/wp-content/uploads/2022/06/Matoate_025.png" alt="" class="wp-image-541" width="658" height="475" srcset="https://d9m.one/wp-content/uploads/2022/06/Matoate_025.png 877w, https://d9m.one/wp-content/uploads/2022/06/Matoate_025-300x217.png 300w, https://d9m.one/wp-content/uploads/2022/06/Matoate_025-768x554.png 768w" sizes="(max-width: 658px) 100vw, 658px" /></a><figcaption>【金結果制御】金のマトに結果テキスト表示スクリプトを割り当て、金結果UIを表示対象に設定</figcaption></figure>



<ol class="wp-block-list"><li>プロジェクトの「Assets&gt;Result」をヒエラルキーの「Gold」にドラッグ＆ドロップ</li><li>ヒエラルキーの「Gold」をクリック</li><li>ヒエラルキーの「Canvas&gt;TextGold」をインスペクターの「Result&gt;Ui Text」にドラッグ＆ドロップ</li><li>CTRLキーを押しながらSキーを押す</li><li>エディタ上中央の「▶」をクリック</li><li>球を金のマトに当てたら「Gold!」と表示されることを確認</li><li>球を金のマトに当てたら球の動きが止まることを確認</li><li>エディタ上中央の「▶」をクリック</li></ol>
</div>



<div style="height:16px" aria-hidden="true" class="wp-block-spacer"></div>



<h3 class="has-background has-medium-font-size wp-block-heading" style="background-color:#e5f7fd"><span id="toc14">●リスタートボタン作成</span></h3>



<div style="height:16px" aria-hidden="true" class="wp-block-spacer"></div>



<div class="wp-block-group is-layout-flow wp-block-group-is-layout-flow">
<h4 class="wp-block-heading"><span id="toc15">▷リスタートボタン作成</span></h4>



<p>UIボタンを「幅80、高さ40、左上寄せ」で作成、ボタンテキストを「Play」に設定します。</p>



<figure class="wp-block-image size-full is-resized"><a href="https://d9m.one/wp-content/uploads/2022/06/Matoate_026.png"><img decoding="async" src="https://d9m.one/wp-content/uploads/2022/06/Matoate_026.png" alt="" class="wp-image-543" width="658" height="475" srcset="https://d9m.one/wp-content/uploads/2022/06/Matoate_026.png 877w, https://d9m.one/wp-content/uploads/2022/06/Matoate_026-300x217.png 300w, https://d9m.one/wp-content/uploads/2022/06/Matoate_026-768x554.png 768w" sizes="(max-width: 658px) 100vw, 658px" /></a><figcaption>【リスタートボタン作成】UIボタンを「幅80、高さ40、左上寄せ」で作成、ボタンテキストを「Play」に設定</figcaption></figure>



<ol class="wp-block-list"><li>ヒエラルキー左上の「＋」をクリックし、「UI＞ボタン &#8211; TextMeshPro」をクリック</li><li>「Restart」と入力し、ENTERキーを押す</li><li>インスペクターの「Rect Transform&gt;アンカープリセット」をクリックし、SHIFTキーとAltキーを押しながら「top-left」をダブルクリック</li><li>インスペクターの「Rect Transform&gt;幅」を(80)に設定</li><li>インスペクターの「Rect Transform&gt;高さ」を(40)に設定</li><li>ヒエラルキーの「Canvas&gt;Restart」左にある「▶」をクリック</li><li>ヒエラルキーの「Canvas&gt;Restart&gt;Text (TMP)」をクリック</li><li>インスペクターの「TextMeshPro&gt;TextInput」下にあるテキスト入力に「Play」と入力</li><li>CTRLキーを押しながらSキーを押す</li></ol>



<h4 class="wp-block-heading"><span id="toc16">▷リスタート制御準備</span></h4>



<p>自分シーンを再読み込みする機能を持ったスクリプトを作成し、UIボタンに割り当てます。</p>



<figure class="wp-block-image size-full is-resized"><a href="https://d9m.one/wp-content/uploads/2022/06/Matoate_027.png"><img decoding="async" src="https://d9m.one/wp-content/uploads/2022/06/Matoate_027.png" alt="" class="wp-image-548" width="658" height="475" srcset="https://d9m.one/wp-content/uploads/2022/06/Matoate_027.png 877w, https://d9m.one/wp-content/uploads/2022/06/Matoate_027-300x217.png 300w, https://d9m.one/wp-content/uploads/2022/06/Matoate_027-768x554.png 768w" sizes="(max-width: 658px) 100vw, 658px" /></a><figcaption>【リスタート制御準備】自分シーンを再読み込みする機能を持ったスクリプトを作成し、UIボタンに割り当て</figcaption></figure>



<ol class="wp-block-list"><li>プロジェクトの「Assets」を右クリックし、「作成＞C# スクリプト」をクリック</li><li>「Restart」と入力し、ENTERキーを押す</li><li>プロジェクトの「Assets&gt;Restart」をヒエラルキーの「Canvas&gt;Restart」にドラッグ＆ドロップ</li><li>CTRLキーを押しながらSキーを押す</li></ol>



<h4 class="wp-block-heading"><span id="toc17">▷リスタート制御</span></h4>



<p>自分シーンを再読み込みする機能を持ったスクリプトを作成し、UIボタンに割り当てます。</p>



<figure class="wp-block-image size-full is-resized"><a href="https://d9m.one/wp-content/uploads/2022/06/Matoate_028.png"><img decoding="async" src="https://d9m.one/wp-content/uploads/2022/06/Matoate_028.png" alt="" class="wp-image-549" width="658" height="475" srcset="https://d9m.one/wp-content/uploads/2022/06/Matoate_028.png 877w, https://d9m.one/wp-content/uploads/2022/06/Matoate_028-300x217.png 300w, https://d9m.one/wp-content/uploads/2022/06/Matoate_028-768x554.png 768w" sizes="(max-width: 658px) 100vw, 658px" /></a><figcaption>【リスタート制御】自分シーンを再読み込みする機能を持ったスクリプトを作成し、UIボタンに割り当て</figcaption></figure>



<ol class="wp-block-list"><li>プロジェクトの「Assets&gt;Restart」をダブルクリック</li><li>名前空間の宣言に「SceneManagement」の宣言を追加</li><li>ボタンから呼び出す関数を定義</li><li>「ボタンから呼び出す関数」に以下の処理を記述</li><li>・現在のシーン名を取得</li><li>・現在のシーン名を読み込む</li><li>Unityエディタにフォーカスを移す</li><li>ヒエラルキーの「Canvas&gt;Restart」をクリック</li><li>インスペクターの「Button&gt;クリック時 ()」右下にある「＋」をクリック</li><li>インスペクターの「Button&gt;クリック時 ()」に追加された枠の左下にヒエラルキーの「Canvas&gt;Restart」をドラッグ＆ドロップ</li><li>インスペクターの「Button&gt;クリック時 ()」に追加された枠の右上にあるドロップダウンをクリックし、「Restart&gt;Run ()」をクリック</li><li>CTRLキーを押しながらSキーを押す</li><li>エディタ上中央の「▶」をクリック</li><li>Playボタンをクリックするとやり直せることを確認</li><li>エディタ上中央の「▶」をクリック</li></ol>



<h4 class="wp-block-heading"><span id="toc18">▷リスタート制御</span></h4>



<p>スクリプトの記述例です。</p>



<div class="hcb_wrap"><pre class="prism line-numbers lang-plain" data-file="Restart.cs"><code>using System.Collections;
using System.Collections.Generic;
using UnityEngine;
// 名前空間「SceneManagement」の宣言
using UnityEngine.SceneManagement;

public class Restart : MonoBehaviour
{
    // Start is called before the first frame update
    void Start()
    {
        
    }

    // Update is called once per frame
    void Update()
    {
        
    }

    // ボタンから呼び出す関数を定義
    public void Run()
    {
        // 現在のシーン名を取得
        string sceneName = SceneManager.GetActiveScene().name;
        // 現在のシーン名を読み込む
        SceneManager.LoadScene(sceneName);
    }
}</code></pre></div>



<div style="height:16px" aria-hidden="true" class="wp-block-spacer"></div>



<p class="has-text-align-center has-x-large-font-size">完成！</p>
</div>



<p>作成手順を書いた記事です。</p>



<p>　　　<a href="https://d9m.one/proc_matoate/">→紹介</a><br>　　　<a href="https://d9m.one/proc_pinball1/">→１／２　オブジェクト作成</a><br>今▷　<a href="https://d9m.one/proc_pinball2/">→２／２　オブジェクト機能</a></p>



<p><a href="https://d9m.one/proc_matoate_full/">完全手順</a><br>※紹介と１～２の手順を１ページにまとめています。<br>　読み込みに時間がかかるかも知れません。</p>
<p>投稿 <a href="https://d9m.one/proc_matoate2/">【基本操作】的当てゲーム～２／２　ゲーム制御【アクション】</a> は <a href="https://d9m.one">だくまたゲーム制作ブログ</a> に最初に表示されました。</p>
]]></content:encoded>
					
					<wfw:commentRss>https://d9m.one/proc_matoate2/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
