続きです。Project:Roll-a-Ballの
Displaying text
を見ました。
<GUI Textを設置> プレイヤーが拾った数を示すカウンターと、全てのCubeを拾ったときに出る「YOU WIN!」というメッセージをGUI Textを使って表示するようにします。
カウンターは左上に、Winメッセージは中央少し上に表示するように位置調整します。その時、Inspector内のPixel Offsetで微調整できます。
・カウンター

・Winメッセージ

<GUI Textを表示するスクリプト(C#)> PlayerController.csに付け足します。(緑字)
using UnityEngine;
using System.Collections;
public class PlayerController : MonoBehaviour
{
public float speed;
public GUIText countText; public GUIText winText; public int count;
void Start () { count = 0; SetCountText (); winText.text = ""; }
void FixedUpdate ()
{
float moveHorizontal = Input.GetAxis("Horizontal");
float moveVertical = Input.GetAxis ("Vertical");
Vector3 movement = new Vector3(moveHorizontal, 0.0f, moveVertical);
rigidbody.AddForce(movement * speed * Time.deltaTime,ForceMode.Acceleration);
}
void OnTriggerEnter(Collider other)
{
if(other.gameObject.tag == "PickUp")
{
other.gameObject.SetActive(false);
count +=1; SetCountText (); }
}
void SetCountText () { countText.text = "Count : " + count.ToString(); if(count >= 12) { winText.text = "YOU WIN!"; } }}
<GUI Textをドロップ> プレイヤーを選択後、それぞれの変数にGUI Textをドロップします。

これでゲーム完成のようですね!。あと1回講座が残ってます。もう少し、もう少し...
。-----------------
<ご注意>私自身が全くの超初心者ですので、文中まちがいがあるかも知れません。その際はご容赦をお願いします。<(_ _)>
-----------------
unity HP のチュートリアル 8 Project:Roll-a-Ballの
Publishing the game
を見ましたが、ゲームをスタンドアロンやWeb Player仕様にする方法は今までにやりましたし、ネット上にも沢山ありますので省略します。
------------------
posted by Shindo Izo at 19:40|
Comment(0)
|
Unityのお勉強 Part II
|