<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Unity - Medium]]></title>
        <description><![CDATA[unity study - Medium]]></description>
        <link>https://medium.com/will-unity?source=rss----9e454beb022---4</link>
        <image>
            <url>https://cdn-images-1.medium.com/proxy/1*TGH72Nnw24QL3iV9IOm4VA.png</url>
            <title>Unity - Medium</title>
            <link>https://medium.com/will-unity?source=rss----9e454beb022---4</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Thu, 19 Nov 2026 21:06:18 GMT</lastBuildDate>
        <atom:link href="https://medium.com/feed/will-unity" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[關於NullReferenceException的問題]]></title>
            <link>https://medium.com/will-unity/%E9%97%9C%E6%96%BCnullreferenceexception%E7%9A%84%E5%95%8F%E9%A1%8C-9e632ee51553?source=rss----9e454beb022---4</link>
            <guid isPermaLink="false">https://medium.com/p/9e632ee51553</guid>
            <category><![CDATA[unity]]></category>
            <category><![CDATA[unity3d]]></category>
            <dc:creator><![CDATA[陳威寰]]></dc:creator>
            <pubDate>Thu, 23 Jan 2020 18:29:50 GMT</pubDate>
            <atom:updated>2020-01-23T18:29:52.020Z</atom:updated>
            <content:encoded><![CDATA[<p>在製作Unity遊戲的過程中，常常遇到很多麻煩，尤其是像我這個例子:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/850/1*K-ttJI1Jap9GhU06sRBuTw.png" /></figure><p>圖片中，我操控的腳色要砍向那隻小怪，本來以為會很順的砍下去，但卻不知道為甚麼遊戲突然暫停了，再看看我當下的程式碼:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e115004833c97654baa20787b474a083/href">https://medium.com/media/e115004833c97654baa20787b474a083/href</a></iframe><pre>using System.Collections;</pre><pre>using System.Collections.Generic;</pre><pre>using UnityEngine;</pre><pre>public class Damage : MonoBehaviour</pre><pre>{</pre><pre>public float damage = 5;</pre><pre>}</pre><p>上面是該小怪的程式碼，下面是上面那個程式所reference的程式，看起來很正常對吧?但執行起來就是會出現那一行訊息。</p><p>所以我查了一下資料:</p><p><a href="https://support.unity3d.com/hc/en-us/articles/206369473-NullReferenceException">NullReferenceException</a></p><p>基本上這個問題就是當你用我上面那個方法的時候，Unity會找不到你要reference的那個腳本在哪，所以我修改了一下我的程式碼:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/193ba45eed6bbcfe631759a366de063c/href">https://medium.com/media/193ba45eed6bbcfe631759a366de063c/href</a></iframe><p>可以看到我把在Awake()函式中做了一些修改，因為我把腳本Damage套在主角SKELETON上，所以必須要讓系統找到SKELETON，它才能再找到Damage這個腳本，之後便能順利運行啦。</p><p>以上就是我這次的分享。</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9e632ee51553" width="1" height="1" alt=""><hr><p><a href="https://medium.com/will-unity/%E9%97%9C%E6%96%BCnullreferenceexception%E7%9A%84%E5%95%8F%E9%A1%8C-9e632ee51553">關於NullReferenceException的問題</a> was originally published in <a href="https://medium.com/will-unity">Unity</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[第一次學習報告]]></title>
            <link>https://medium.com/will-unity/%E7%AC%AC%E4%B8%80%E6%AC%A1%E5%AD%B8%E7%BF%92%E5%A0%B1%E5%91%8A-39f902af7db?source=rss----9e454beb022---4</link>
            <guid isPermaLink="false">https://medium.com/p/39f902af7db</guid>
            <dc:creator><![CDATA[廖書賢]]></dc:creator>
            <pubDate>Sat, 16 Nov 2019 08:31:19 GMT</pubDate>
            <atom:updated>2019-11-16T08:31:19.335Z</atom:updated>
            <content:encoded><![CDATA[<p>— — — — — — — — — — — — — —基本篇 — — — — — — — — — — — — — —</p><p>★如何載入資源?</p><p>Window底下有個Assets store將它點開<br> 接著搜尋自己想要的內容並下載</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/538/1*0mXQNlbxYDrz0QHHkw21zQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*imAmWeK02-iD2pNaJ51FoA.png" /></figure><p>右上角有個自己帳號的圖樣，把它點開往下滑，就可以找到My Assets，接著按Import匯入現在開啟的Unity即可</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*RPjyBzqFfrE_VP1XLlweJg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*dFlvczZRrezJtMKD-nOKeA.png" /></figure><p>★ 基本物件移動</p><p>•需要透過腳本移動到遊戲物件上才能套用</p><p>•常用腳本指令:接收按鍵</p><p>Input.GetKey()為鍵盤輸入，()可填入按鍵並要用雙引號包住Input.GetMouseButton()為滑鼠輸入，()可填入0、1、2分別代表滑鼠左鍵、右鍵、滾輪</p><p>GetKey或GetMouseButton後面加上Up或Down代表放開或按下時只觸發一次效果而已</p><p>•常用腳本指令:物體移動</p><p>transform.Translate(x,y,z)為移動</p><p>transform.Rotate(x,y,z)為旋轉</p><p>x,y,z分別為三個軸向</p><p>★腳本中啟用/關閉自己的物件/元件</p><p>•如果是GameObject想要顯示或隱藏起來</p><p>GameObject.SetActive(true/false);</p><p>•如果是GameObject底下的Component要決定是否啟用</p><p>Component.enabled=true/false;</p><p>★加入天空盒</p><p>•隨著Unity版本更新，許多選單設置有些改變</p><ul><li>在Window底下Rendering有個Lighting Settings，針對Skybox Material加入需要素材即可</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/701/1*cFufnr3Z5R1P0Jdy3L-ENA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/615/1*DcdhzDgw-wAyRR8dPIN8Bw.png" /></figure><p>★地形工具</p><ul><li>地形工具舊版的升降工具、高度工具、柔化工具等等按鈕已經消失，現在可以在Paint Terrain按鈕底下找到選單並使用對應功能</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/406/1*wguqcdq9TcuHg2kz46Q1wQ.png" /></figure><p>— — — — — — — — — — — — — — 探討篇— — — — — — — — — — — — — —</p><p>★簡單的第一、三人稱相機視角</p><p>•我們不管在RPG、TPS、FPS或任何操作物件的遊戲，常常會需要使用到第一人稱視角或第三人稱視角</p><p>•一個簡單的方法是，讓camera成為我們要追蹤的遊戲物件底下的子物體，也就是讓camera在遊戲物件的階層之下</p><p>•將camera移動到適當的位置，產生第一人稱或第三人稱視角的效果</p><ul><li>作為基本功能已經相當足夠，但如果希望畫面上能顯示更多東西或是希望相機移動不要那麼死板，需要更多進階設定</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/952/1*5tH1Od1Zjc_aJoqGeL3S_w.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*GoR2uCG9iPP9Lvx-eIon2Q.png" /><figcaption>•EX:Camera會追隨上面階層的遊戲物件移動</figcaption></figure><p>★UI上的button突然按不到?</p><p>•先儲存現有變更後，重啟Unity看看有沒有回復</p><p>•檢查一下hierarchy上的EventSystem是否有被誤刪，如果不見就新創一個預設的EventSystem</p><p>•檢查各Canvas的order順序是否有影響到</p><ul><li>檢查Button指定的onclick事件上的物件是否連結失效</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/311/1*cDtf5RqFMmtDIjT3jmldXg.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=39f902af7db" width="1" height="1" alt=""><hr><p><a href="https://medium.com/will-unity/%E7%AC%AC%E4%B8%80%E6%AC%A1%E5%AD%B8%E7%BF%92%E5%A0%B1%E5%91%8A-39f902af7db">第一次學習報告</a> was originally published in <a href="https://medium.com/will-unity">Unity</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[如何做PPT]]></title>
            <link>https://medium.com/will-unity/%E5%A6%82%E4%BD%95%E5%81%9Appt-c1ba02a38f20?source=rss----9e454beb022---4</link>
            <guid isPermaLink="false">https://medium.com/p/c1ba02a38f20</guid>
            <dc:creator><![CDATA[邱繼祥]]></dc:creator>
            <pubDate>Mon, 11 Nov 2019 15:05:51 GMT</pubDate>
            <atom:updated>2019-11-11T15:10:14.998Z</atom:updated>
            <content:encoded><![CDATA[<p>分享一些做ppt的經驗</p><h3>最忌諱自己講得天花亂墜台下根本聽不懂</h3><p><strong>一.不要只有一張圖然後看圖說故事</strong><br>1.老師學長不懂你想表達什麼</p><p>2.同學可能會理解錯誤</p><p>利用簡單圖示說明自己要表達的(可以做逐步動畫最好)</p><p>範例:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*bA7inhrcThD4QfFgpTWGWA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gEZQ91qAwCI1kOSILncz7A.png" /></figure><p>逐步動畫</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gYUV0Gcg675dKSbG6PbM3Q.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*NOF9Hy0CLH_CQnTcjV5Cqw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*JGdHA2DkucMlIU6v1pn7-Q.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wOmkHbjU7vwO0vtUif_gyw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qJXMi0UpPghK6ZvxaqimGQ.png" /></figure><p><strong>二.盡量不要直接貼整頁程式碼</strong></p><p>除非真的需要特別強調內容<br>不然建議寫出你的邏輯作法、虛擬碼、流程圖<br>並且可以搭配圖示</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*HKoqLR_byT6IT-sPQgVQDg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/552/1*DhyspTtXueHAxa2wUFxfZA.png" /></figure><p><strong>三.利用表格、列點、整齊的箭頭等方式簡單清楚表達</strong><br>不要讓ppt充滿沒有排版的文字<br>簡報要的是清楚明白易懂的內容</p><p>範例:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*FrxjFxsBRhVM_yajJ3DkRw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6P-jk6wQSFhZXZ2ZOtbRoA.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c1ba02a38f20" width="1" height="1" alt=""><hr><p><a href="https://medium.com/will-unity/%E5%A6%82%E4%BD%95%E5%81%9Appt-c1ba02a38f20">如何做PPT</a> was originally published in <a href="https://medium.com/will-unity">Unity</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Unity-UI(image、text)]]></title>
            <link>https://medium.com/will-unity/unity-ui-image-text-794b5974f79b?source=rss----9e454beb022---4</link>
            <guid isPermaLink="false">https://medium.com/p/794b5974f79b</guid>
            <dc:creator><![CDATA[邱繼祥]]></dc:creator>
            <pubDate>Sun, 18 Aug 2019 05:42:57 GMT</pubDate>
            <atom:updated>2019-09-25T01:49:07.048Z</atom:updated>
            <content:encoded><![CDATA[<p>我們常常會使用到UI的功能<br>雖然可能在初始狀態就設置好顏色、文字<br>但是我們仍有很多時候會需要透過腳本動態設置顏色以及文字內容<br>以下為使用方法</p><p>動態跟換文字內容</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/346/1*1wGcSbI0UM4axUT9Jf8jCQ.jpeg" /></figure><pre>this.gameObject.GetComponent&lt;Text&gt;().text = &quot;要改的文字&quot;;</pre><p>this.gameObject指的就是我們的Text物件<br>GetComponent就是用來截取物件底下組件的方法，與截取腳本方法相同，在此我們要截取Text組件<br>text是我們Text組件裡的其中一個欄位<br>再來就是=設值</p><p>更改顏色方法</p><blockquote>Image</blockquote><pre>Image.gameObject.GetComponent&lt;Image&gt;().color = new Color(R/255f,G/255f,B/255f, A/255f);</pre><blockquote>Text</blockquote><pre>Text.gameObject.GetComponent&lt;Text&gt;().color = new Color(R/255f,G/255f,B/255f, A/255f);</pre><p>如果我們使用的為0~255為範圍則要表示為 數字/255f<br>因為在此我們是以0~1為色彩範圍</p><p>順帶一提<br>在openGL裡定義色彩範圍也是一樣:</p><pre><strong>glColor3f(r, g, b); </strong>// Color=[r, g, b], 0≤ r, g, b ≤1</pre><pre><strong>glColor4f(r, g, b, <em>a</em>); </strong>// Color + opacity. 0≤ <em>a </em>≤1</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=794b5974f79b" width="1" height="1" alt=""><hr><p><a href="https://medium.com/will-unity/unity-ui-image-text-794b5974f79b">Unity-UI(image、text)</a> was originally published in <a href="https://medium.com/will-unity">Unity</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Unity-TheFirst(08/16)]]></title>
            <link>https://medium.com/will-unity/unity-thefirst-08-16-bd2a616c9ce3?source=rss----9e454beb022---4</link>
            <guid isPermaLink="false">https://medium.com/p/bd2a616c9ce3</guid>
            <dc:creator><![CDATA[邱繼祥]]></dc:creator>
            <pubDate>Fri, 16 Aug 2019 15:28:19 GMT</pubDate>
            <atom:updated>2019-10-19T07:40:21.491Z</atom:updated>
            <content:encoded><![CDATA[<h3>Unity-TheFirst(10/19)</h3><p><strong>1.</strong>首先希望你們可以辦一個medium的帳號<br>在這裡紀錄你們的學習內容大家互相分享<br>我需要你們的medium帳號(@部分)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/446/1*OyosbSB6codTw2BFfGhf0Q.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/609/1*xo_CPXv7tSsiMPV6-VkS7A.jpeg" /></figure><p><strong>2.</strong>我會將你們加入這個unity的publication<br>以後你們發表文章後可以按...&gt;Add to publication<br>這樣就有一個共同創作分享文章的空間</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/1*MD_74NYq7xaUnMo0Rg3nLA.jpeg" /></figure><p><strong>3.</strong>發布文章實請用&quot;固定tag&quot;看要取什麼都可以主要是medium可以依照tag分類</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/853/1*bO7Zc_R9xKSV63rKKb69ew.jpeg" /></figure><p><strong>4.</strong>如果發表的內容不適合公開(學校專案等)需要設定不公開</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/271/1*9kPiCS_R6q3AwgCdT5Me-Q.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/266/1*UmK1LxDnUjZjjBa0hT26aQ.jpeg" /></figure><p>一開始在接觸unity時，一定會很沒想法方向，所以我直接給一個目標方向</p><h3>讓一個物件可以透過你的鍵盤控制方向移動</h3><p>首先大概可以分幾個方向來切入</p><blockquote>物件</blockquote><ol><li>可以先了解物件是什麼，而該如何使用物件，在unity裡面每一個看到的東西都是物件</li><li>最常使用的例如:位置:GameObject.transform.position、隱藏GameObject.SetActive(false)、尋找物件:GameObject.Find(“…”)</li></ol><blockquote>腳本</blockquote><ol><li>物件的任何行為都需要腳本控制，也就是程式碼，應該很好理解</li><li>常使用到的例如:腳本呼叫腳本函式:GetComponent</li></ol><blockquote>鍵盤</blockquote><p>1.了解一下如何使用鍵盤的程式語法</p><blockquote>移動</blockquote><ol><li>Translate、rotate</li></ol><blockquote>碰撞</blockquote><ol><li>Trigger、Collider、Rigibody</li></ol><p>可以先了解這些簡單內容，當然只是了解沒什麼用，要做，依照 &quot;讓一個物件可以透過你的鍵盤控制方向移動&quot; 這個方向去實踐，想辦法解決所遇到的總總問題，Unity教學文很多多到真的很容易學，不會就提出來，不用擔心問題白不白癡，學長也是一路白癡過來，寧願發問也不要自己瞎忙壓力大然後什麼都沒有。</p><p>了解大概內容後就可以實作，其實我很建議都不要了解直接實作，遇到問題再去學比較容易記住，只是看看了解反而會知道道理但是不知道該怎麼用</p><p>然後我就不多手把手了，好好玩unity吧!玩久了真的香</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=bd2a616c9ce3" width="1" height="1" alt=""><hr><p><a href="https://medium.com/will-unity/unity-thefirst-08-16-bd2a616c9ce3">Unity-TheFirst(08/16)</a> was originally published in <a href="https://medium.com/will-unity">Unity</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Unity-Coroutines]]></title>
            <link>https://medium.com/will-unity/unity-coroutines-470c396f161?source=rss----9e454beb022---4</link>
            <guid isPermaLink="false">https://medium.com/p/470c396f161</guid>
            <dc:creator><![CDATA[邱繼祥]]></dc:creator>
            <pubDate>Fri, 02 Aug 2019 03:02:36 GMT</pubDate>
            <atom:updated>2019-08-02T06:51:39.305Z</atom:updated>
            <content:encoded><![CDATA[<p><a href="https://wuzhiwei.net/unity_coroutines/">https://wuzhiwei.net/unity_coroutines/</a></p><p>在Unity中，一般的方法都是順序執行的，一般的方法也都是在一幀中執行完畢的，當我們所寫的方法需要耗費一定時間時，便會出現幀率下降，畫面卡頓的現象。例如當我們調用一個方法想要讓一個物體緩慢消失時，除了在Update中執行相關操作外，Unity還提供了更加便利的方法，這便是協程。</p><p>Coroutines翻譯過來就是協程，和線程(Threads)是兩個<strong>完全不同</strong>的概念。</p><p>線程是完全異步的，在多核CPU上可以做到真正的並行。正是由於完全並行的自由，導致線程的編程特別麻煩。</p><p>比如：A線程在讀取一個變量的值時，B線程可能正在給這個變量重新賦值，導致A線程讀到的值並不准確。為了保證一個變量同一時刻只有一個線程訪問，需要給變量加上鎖，當線程訪問完畢後又需要記得解鎖。</p><p>協程則是在線程中執行的一段代碼，它並不能做到真正異步。協程的代碼可以只執行其中一部分，然後<strong>掛起</strong>，等到未來一個恰當時機再從原來掛起的地方<strong>繼續向下執行</strong>。</p><p>Unity中的協程就用到了yield return語句， Unity是在遊戲的<strong>每一幀</strong>（frame）中去檢查是否需要從掛起恢復繼續向下執行</p><pre>void Start ()<br>{<br>  StartCoroutine(ReturnNull());<br>  print(“Start Ends”);<br>}<br>void Update ()<br>{<br>  print(“Update”);<br>}<br>IEnumerator ReturnNull()<br>{<br>  print(“ReturnNull Invoked”);<br>  while(true)<br>  {<br>     print(“before yield return null”);<br>     yield return null;<br>     print(“after yield return null”);<br>  }<br>}</pre><p>結果</p><pre>ReturnNull Invoked<br>before yield return null<br>Start Ends<br>Update<br>Update<br>after yield return null<br>before yield return null<br>Update<br>after yield return null<br>before yield return null<br>Update<br>after yield return null<br>before yield return null<br>Update</pre><pre>after ...</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=470c396f161" width="1" height="1" alt=""><hr><p><a href="https://medium.com/will-unity/unity-coroutines-470c396f161">Unity-Coroutines</a> was originally published in <a href="https://medium.com/will-unity">Unity</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Unity-UI-Text]]></title>
            <link>https://medium.com/will-unity/unity-ui-text-48d2d97a4299?source=rss----9e454beb022---4</link>
            <guid isPermaLink="false">https://medium.com/p/48d2d97a4299</guid>
            <category><![CDATA[unity]]></category>
            <dc:creator><![CDATA[邱繼祥]]></dc:creator>
            <pubDate>Tue, 23 Jul 2019 03:47:47 GMT</pubDate>
            <atom:updated>2019-07-23T03:47:47.677Z</atom:updated>
            <content:encoded><![CDATA[<p>如何再程式碼裡更改Text的內容</p><p>舉例:修改A物件底下的Text</p><pre>GameObject.Find(&quot;A&quot;).GetComponent&lt;Text&gt;().text=&quot;內容&quot;</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=48d2d97a4299" width="1" height="1" alt=""><hr><p><a href="https://medium.com/will-unity/unity-ui-text-48d2d97a4299">Unity-UI-Text</a> was originally published in <a href="https://medium.com/will-unity">Unity</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Unity-碰撞]]></title>
            <link>https://medium.com/will-unity/unity-%E7%A2%B0%E6%92%9E-4a47056cf8e9?source=rss----9e454beb022---4</link>
            <guid isPermaLink="false">https://medium.com/p/4a47056cf8e9</guid>
            <category><![CDATA[unity]]></category>
            <dc:creator><![CDATA[邱繼祥]]></dc:creator>
            <pubDate>Tue, 23 Jul 2019 02:59:02 GMT</pubDate>
            <atom:updated>2019-11-16T08:38:12.334Z</atom:updated>
            <content:encoded><![CDATA[<p>原文: <a href="https://blog.csdn.net/andyhan_1001/article/details/76286018">https://blog.csdn.net/andyhan_1001/article/details/76286018</a></p><h4>本篇目的:解決CharacterController碰撞帶有isTrigger的collider穿透問題</h4><h3>Rigidbody</h3><p>用在本身不會活動的“物體”上，他們是靠物理系統運動。</p><p>不要使用Translate()來讓物體運動，要用各種“力”, 例如：Rigidbody的AddForce()方法，通過“力”來讓它移動。</p><p>Rigidbody可以和NavMeshObstacle合用，因為後者也是用在“物體”上的，但是一般不要和NavMeshAgent合用，因為這兩個都會控制物體的運動，這樣會有race condition。如果非要合用，請勾選Is Kinematic，由此看來如果Rigidbody的Is Kinematic屬性被勾選了，那麼Rigidbody就可以和任何其他的Component合用了，比如：NavMeshAgent，CharacterController。</p><p>Rigidbody會對“力”產生響應，如果一個物體加上了Rigidbody，首先會直接對“重力”產生響應，如果再加上Collider，就會對其他“力”產生響應了。同時如果使用Translate()移動Rigidbody，那麼它會對其他的Rigidbody在碰撞的時候自動施加一個“力”。</p><h3>Collider</h3><p>Collider是碰撞檢測的基礎。</p><p>Collider分為static collider和dynamic collider</p><h4>static collider:</h4><p>指的是相互碰撞的兩個物體沒有附加剛體而只附加了Collider的遊戲對象。這類對像在碰撞時會保持靜止，發生碰撞時不會觸發任何的方法函數</p><p>沒有Rigidbody的collider，最好是靜止的物體，不要通過改變他的transform的position來使它運動，這樣不僅會給物理引擎造成很多性能損失，而且會產生一些無法預測的行為。</p><p>#註 : 非要通過Translate( )移動，且不希望被物理引擎控制，則需要加上一個勾選了Is Kinematic的Rigidbody(Is Kinematic是讓Rigidbody不受物理引擎的控制)</p><h4>dynamic collider:</h4><p>有Rigidbody的collider</p><p>在靜態碰撞器的基礎上，處於運動狀態的物體必須要附加剛體組件和帶有碰撞檢測函數的腳本，被撞的物體可以沒有剛體組件或碰撞檢測腳本。 當兩個物體發生碰撞時，帶有剛體組件的物體會發生物理特性，如被撞飛，或有摩擦力的影響下移動一段距離。</p><h3>CharacterController</h3><p>不對任何“力”產生作用，同時也不對物體施加“力”，即使物體是Rigidbody。</p><p>（不要再加Collider，CharacterController有自帶的Capsule Collider。並且使用Move()方法移動物體）</p><h3>*重點</h3><p>Collider中Is Trigger的優先級高於Rigidbody（不管這個被標記為Is Trigger的Collider和Rigidbody是不是在同一個GameObject上）</p><p>因為Rigidbody是根據Collider來進行物理模擬，Collider是Rigidbody的基礎</p><h4>為何CharacterController碰撞帶有isTrigger的collider會穿透?</h4><p>Collider中Is Trigger的優先級也高於CharacterController，不過Collider和CharacterController一般不放在一起，所以這裡指的是對方的物體上Collider的Is Trigger。</p><p>由於Trigger只是通過OnTriggerEnter()、OnTriggerStay()、OnTriggerOut()來響應碰撞行為</p><p>如果被碰撞的物體Collider的Is Trigger方法勾選了，那麼由於Is Trigger只是將Collider當成了一個“觸發器”，不會響應任何實質碰撞（所謂的實質碰撞，就是能被觀察到的碰撞，比如<strong>碰撞之後產生運動</strong>，<strong>碰撞之後阻止物體穿過</strong>等等）。所以就算Rigidbody在，也發揮不了作用（OnCollisionEnter()、OnCollisionStay()、OnCollisionOut()不會調用，同時也不會產生物理運動，也不會阻止物體穿過，反正任何可見的碰撞效果都沒有）。</p><p>所以CharacterController會穿過被碰撞的物體，並且<strong>OnControllerColliderHit()</strong>這個回調不會起作用，取而代之的是雙方的OnTrigger*()函數會被調用。</p><h4>如何解決?</h4><p>CharacterController 碰撞物體，如果被碰撞的物體有Collider，並且Is Trigger沒有勾選，那麼無論這個物體是不是Rigidbody，CharacterController都會被這個物體“擋”下來，並且只會觸發他自己的<strong>OnControllerColliderHit( )</strong>這個回調函數（也就是說，如果被碰撞的物體或者它自己有OnTrigger*()，OnCollision*()這種函數，都不會被觸發）。</p><p>所以如果我們想要實現一個CharacterController推箱子的遊戲，那麼首先這個箱子必須是Rigidbody，並且Collider不是Is Trigger，而這個“推力”需要在CharacterController的OnControllerColliderHit()這個函數中“發出”了。</p><h4>判斷碰撞物</h4><pre>void OnControllerColliderHit(ControllerColliderHit hit)<br>{</pre><pre>    if (hit.gameObject.tag==””){要做的事}</pre><pre>}</pre><p>鏡頭不穿牆教學 <a href="https://www.youtube.com/watch?v=CZ9SzK5jeWo&amp;t=208s">https://www.youtube.com/watch?v=CZ9SzK5jeWo&amp;t=208s</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4a47056cf8e9" width="1" height="1" alt=""><hr><p><a href="https://medium.com/will-unity/unity-%E7%A2%B0%E6%92%9E-4a47056cf8e9">Unity-碰撞</a> was originally published in <a href="https://medium.com/will-unity">Unity</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>