Related Posts Plugin for WordPress, Blogger...

1-3 Pan And Tilt Camera Options

這個單元要來玩玩Unity為我們提供的相機prefab,首先先把我們自己製作的相機拉到下面的Project視窗,他會變成一個prefab物件。
這時,把相機從場景中移除後,再執行遊戲,會發現視窗上告訴你沒有相機了。
此時,你可以再從Project視窗中把剛剛儲存的Camera Arm.prefab移回場景中,就能發現相機仍可以正常運作。


不知道什麼是prefab嗎?
【基本教學】預製物件 - Prefab

GameObject 與 Prefab 的區別與建立

官方說:
It is convenient to build a GameObject in the scene by adding components and setting their properties to the appropriate values. This can create problems, however, when you have an object like an NPC, prop or piece of scenery that is reused in the scene several times. Simply copying the object will certainly produce duplicates but they will all be independently editable. Generally, you want all instances of a particular object to have the same properties, so when you edit one object in the scene, you would prefer not to have to make the same edit repeatedly to all the copies.

Fortunately, Unity has a Prefab asset type that allows you to store a GameObject object complete with components and properties. The prefab acts as a template from which you can create new object instances in the scene. Any edits made to a prefab asset are immediately reflected in all instances produced from it but you can also override components and settings for each instance individually.

簡單來說,prefab可以封裝GameObject,包含裡面的元件、參數、腳本等等,提供給整個專案中需要重複利用的地方。如果用複製貼上的方式,容易造成專案中有多個相同物件的管理上的困難,採用prefab的話,只需要修改prefab就能改動所有專案中採用該prefab的地方。另一個好處是,即便你想針對該prefab在某個特定場景有不同的參數,也是可以分別設定的唷!

接著來匯入Unity提供的相機吧。

 匯入以後就會在Standard Assets/Cameras/Prefabs底下發現四種相機:
1. CctvCamera
2. FreeLookCamera
3. HandheldCamera
4. MultipurposeCamera

今天試用了兩種相機,首先FreeLook相機,除了相機會跟隨著人物角色移動以外,還可以用滑鼠操控不同視角,從各種角度觀察人物角色。類似於ThirdPerson Camera,許多線上遊戲也都是使用這種相機,感謝Unity幫我們寫好了相機!


再來是Multipurpose相機,這種相機就無法用滑鼠操控視角,而是會固定跟隨著人物角色的背後。只不過,當你轉彎時相機不會馬上轉到人物的背後,而是慢慢轉過去。移轉的速度可以由參數進行調整。


Unity的Inspector畫面中可以修改相關參數。對程式碼有興趣的人,也可以點進去看看唷。

留言