Mercurial > hg > Members > kazuma > JungleforUnity
diff Assets/Application/Scripts/Player.cs @ 3:2dd40b4412e4
Create game base.
author | Kazuma |
---|---|
date | Mon, 07 Nov 2016 18:42:01 +0900 |
parents | e5ef0342d00b |
children | 2878be4487ec |
line wrap: on
line diff
--- a/Assets/Application/Scripts/Player.cs Mon Nov 07 02:05:00 2016 +0900 +++ b/Assets/Application/Scripts/Player.cs Mon Nov 07 18:42:01 2016 +0900 @@ -1,5 +1,6 @@ using UnityEngine; using System.Collections; +using System.Collections.Generic; public class Player : MonoBehaviour { // Singleton // -------------------------------------- @@ -7,12 +8,26 @@ private GameObject eye; private CharacterController cc; private Vector3 Direction; + // 今見ているフィールドのアイテム + public GameObject LookedObject; + // セットする前のアイテム + public int HaveObjectNumber; + + public int GlassItem = 0; + public int SandItem = 0; + public int WoodItem = 0; + + public System.Collections.Generic.List<Stage> HaveItemList = new System.Collections.Generic.List<Stage>(); + + public delegate void Callback(int n0, int n1, int n2); + public Callback callback; + // ------------------------------------- private void Start () { if (Instance == null) { Instance = this; } - eye = this.transform.FindChild ("Camera").gameObject; + eye = this.transform.FindChild ("Eye").gameObject; cc = this.GetComponent<CharacterController> (); } @@ -22,7 +37,7 @@ public void Move (bool b) { if (b) { - Direction += this.transform.forward / 10f; + Direction += this.transform.forward * Time.deltaTime; } else { Direction.x = 0; Direction.z = 0; @@ -38,4 +53,56 @@ public void Gravity () { Direction.y = -0.1f; } + + public void SetLookedObject (GameObject obj) { + LookedObject = obj; + } + + public void SetHaveObjectNumber (int num) { + HaveObjectNumber = num; + } + + public void GetItem () { + if (LookedObject != null) { + Stage stage = LookedObject.GetComponent<Stage> (); + HaveItemList.Add (stage); + CheckList (); + stage.Delete (); + } + } + + public void SetItem () { + if (LookedObject != null) { + StageManager.Instance.CreateStage (HaveObjectNumber, new Vector3 (LookedObject.transform.position.x, LookedObject.transform.position.y + 1f, LookedObject.transform.position.z)); + CheckList (); + } + } + + public void CheckList () { // 増えたときに面倒なので動的に増えてもいいように書き直す必要あり + int g = 0; + int w = 0; + int s = 0; + foreach (var item in HaveItemList) { + if (Stage.Type.GRASS == item.Attribute) { + g++; + } else if (Stage.Type.SAND == item.Attribute) { + s++; + } else if (Stage.Type.WOOD == item.Attribute) { + w++; + } + } + SetItemNum (g, w, s); + } + + public void SetCallback (Callback c) { + this.callback = c; + } + + public void SetItemNum (int glass, int wood, int sand) { + this.GlassItem = glass; + this.WoodItem = wood; + this.SandItem = sand; + this.callback (sand, wood, glass); + print (glass + ", " + wood + ", " + sand); + } }