Unity game開発 今日のUnity勉強 基本テンプレート編unity 2017
ゲームアプリを作る時に基本となるテンプレートが必要になります。このテンプレートがアレばすぐにゲーム開発が進められます
ただし全てのゲームジャンルに適用できるわけではなく、ジャンルは限られますけど。
今回は2Dgameとして作成します。
参考にしたのがunity 公式のチュートリアルです。このチュートリアルは英語版になっており英語を聞いても苦にならなければ、公式サイトの方がより丁寧ですのでそちらをご覧ください
今回作成するテンプレートの内容は、シンプルです。
矢印キーを押すとその方向にUFOオブジェクトが動いてある領域で動きが制限されるというものです。
これにより物理演算と衝突を理解できます
物を動かすということが理解できれば、あとはゲームのシナリオに合わせてプログラムをすれば良いのです。
unityでは特にメインループを作らなくても動きます。全体を管理するクラスコードはすぐには必要ありませんが、オブジェクトが増えてくると内容が複雑になり管理するクラスが必要になります
テンプレートではここまでは作りません。
動画
・全体の構成
プレイヤーufoオブジェクト
バックグラウンドオブジェクト
・動きの仕様
プレイヤーが矢印キーを押すと動く
動かせる範囲はバックグラウンドの大きさに制限されるように衝突物を配置
カメラはプレイヤーを追随する
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
using System.Collections; using System.Collections.Generic; using UnityEngine; public class PlayerCollider : MonoBehaviour { private Rigidbody2D rd2d; public float speed; private Vector2 movement; // Use this for initialization void Start () { rd2d = GetComponent<Rigidbody2D>(); } // Update is called once per frame void Update () { float moveVertical = Input.GetAxis("Vertical"); float moveHorizontal = Input.GetAxis("Horizontal"); movement = new Vector2(moveHorizontal,moveVertical); } void FixedUpdate(){ rd2d.AddForce(movement*speed); } } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
using System.Collections; using System.Collections.Generic; using UnityEngine; public class CameraController : MonoBehaviour { public GameObject player; //Public variable to store a reference to the player game object private Vector3 offset; //Private variable to store the offset distance between the player and camera // Use this for initialization void Start () { //Calculate and store the offset value by getting the distance between the player's position and camera's position. offset = transform.position - player.transform.position; } // LateUpdate is called after Update each frame void LateUpdate () { // Set the position of the camera's transform to be the same as the player's, but offset by the calculated offset distance. transform.position = player.transform.position + offset; } } |
2018/01/02
2D Game Creation、Tower Bridge Defense
ここには、以前見た頃があるUnityの2Dゲームのチュートリアルがある
UFOのシーンでえんどう豆みたいなキャラクターが画面を飛び回って敵を倒す。これを参考にする。なおUnityのバージョンが古いので注意する
https://unity3d.com/jp/learn/tutorials/s/2d-game-creation
更に次のチュートリアルへ進む
Scripting Gravity
https://unity3d.com/jp/learn/tutorials/topics/2d-game-creation/scripting-gravity?playlist=17093
ここに、ダウンロードがある
(私はここにダウンロードした
/Users/maseda/Documents/新書類/UnityProgram内)
monoを再度ダウンロードした。
http://www.mono-project.com/download/
から。以前のバージョンが使えなくなったから。
こっちがダメだったので、別の方をダウンロードした。
http://www.monodevelop.com/download/
その後、まだCODE Unity 補完ができない。
一度、DOTNET COREを削除してDOTNET COREを再インストールした
aidayota-no-MacBook-Pro:2DUFO_tut_20180104 maseda$ cd /usr/local/share/dotnet && ls
LICENSE.txt additionalDeps host shared
ThirdPartyNotices.txt dotnet sdk store
aidayota-no-MacBook-Pro:dotnet maseda$ sudo rm -rf dotnet
Password:
aidayota-no-MacBook-Pro:dotnet maseda$ cd /etc/paths.d && ls
dotnet mono-commands
aidayota-no-MacBook-Pro:paths.d maseda$ sudo rm dotnet
aidayota-no-MacBook-Pro:paths.d maseda$
DOTNETを再インストール
https://www.microsoft.com/net/learn/get-started/macos
以下の記事を参考にする。
MacのVisual Studio CodeとUnityを連携させる方法(4)
brewはインストールされているので、
(1)Macのコンソールから
$ brew update
暫く待つ。3分以上は待った記憶がある。
「The reference assemblies for framework “.NETFramework,Version=v3.5” were not found.」
がCODEで表示されていたので、
(2)$ brew install mono
で実行
文字ベースのインジケータが表示されてダウンロード状況がわかります。
しかし、まだエラーが出たまま。
なんだろう。
内容
コードの補完結論
Visual Studioをインストールして
Unityのメニューから
Preference>External Tool>External script Tool でcodeでなくて、Visual Studioを選択する。
これで、コード補完ができた。
Codeのほうが軽快だけど、コード補完がないと文字の打ち間違いが減る。