Mercurial > hg > Members > kazuma > JungleforUnity
comparison 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 |
comparison
equal
deleted
inserted
replaced
2:ca28bf83fc89 | 3:2dd40b4412e4 |
---|---|
1 using UnityEngine; | 1 using UnityEngine; |
2 using System.Collections; | 2 using System.Collections; |
3 using System.Collections.Generic; | |
3 | 4 |
4 public class Player : MonoBehaviour { // Singleton | 5 public class Player : MonoBehaviour { // Singleton |
5 // -------------------------------------- | 6 // -------------------------------------- |
6 public static Player Instance; | 7 public static Player Instance; |
7 private GameObject eye; | 8 private GameObject eye; |
8 private CharacterController cc; | 9 private CharacterController cc; |
9 private Vector3 Direction; | 10 private Vector3 Direction; |
11 // 今見ているフィールドのアイテム | |
12 public GameObject LookedObject; | |
13 // セットする前のアイテム | |
14 public int HaveObjectNumber; | |
15 | |
16 public int GlassItem = 0; | |
17 public int SandItem = 0; | |
18 public int WoodItem = 0; | |
19 | |
20 public System.Collections.Generic.List<Stage> HaveItemList = new System.Collections.Generic.List<Stage>(); | |
21 | |
22 public delegate void Callback(int n0, int n1, int n2); | |
23 public Callback callback; | |
24 | |
10 // ------------------------------------- | 25 // ------------------------------------- |
11 private void Start () { | 26 private void Start () { |
12 if (Instance == null) { | 27 if (Instance == null) { |
13 Instance = this; | 28 Instance = this; |
14 } | 29 } |
15 eye = this.transform.FindChild ("Camera").gameObject; | 30 eye = this.transform.FindChild ("Eye").gameObject; |
16 cc = this.GetComponent<CharacterController> (); | 31 cc = this.GetComponent<CharacterController> (); |
17 } | 32 } |
18 | 33 |
19 private void Update () { | 34 private void Update () { |
20 Gravity (); | 35 Gravity (); |
21 } | 36 } |
22 | 37 |
23 public void Move (bool b) { | 38 public void Move (bool b) { |
24 if (b) { | 39 if (b) { |
25 Direction += this.transform.forward / 10f; | 40 Direction += this.transform.forward * Time.deltaTime; |
26 } else { | 41 } else { |
27 Direction.x = 0; | 42 Direction.x = 0; |
28 Direction.z = 0; | 43 Direction.z = 0; |
29 } | 44 } |
30 cc.Move (Direction); | 45 cc.Move (Direction); |
36 } | 51 } |
37 | 52 |
38 public void Gravity () { | 53 public void Gravity () { |
39 Direction.y = -0.1f; | 54 Direction.y = -0.1f; |
40 } | 55 } |
56 | |
57 public void SetLookedObject (GameObject obj) { | |
58 LookedObject = obj; | |
59 } | |
60 | |
61 public void SetHaveObjectNumber (int num) { | |
62 HaveObjectNumber = num; | |
63 } | |
64 | |
65 public void GetItem () { | |
66 if (LookedObject != null) { | |
67 Stage stage = LookedObject.GetComponent<Stage> (); | |
68 HaveItemList.Add (stage); | |
69 CheckList (); | |
70 stage.Delete (); | |
71 } | |
72 } | |
73 | |
74 public void SetItem () { | |
75 if (LookedObject != null) { | |
76 StageManager.Instance.CreateStage (HaveObjectNumber, new Vector3 (LookedObject.transform.position.x, LookedObject.transform.position.y + 1f, LookedObject.transform.position.z)); | |
77 CheckList (); | |
78 } | |
79 } | |
80 | |
81 public void CheckList () { // 増えたときに面倒なので動的に増えてもいいように書き直す必要あり | |
82 int g = 0; | |
83 int w = 0; | |
84 int s = 0; | |
85 foreach (var item in HaveItemList) { | |
86 if (Stage.Type.GRASS == item.Attribute) { | |
87 g++; | |
88 } else if (Stage.Type.SAND == item.Attribute) { | |
89 s++; | |
90 } else if (Stage.Type.WOOD == item.Attribute) { | |
91 w++; | |
92 } | |
93 } | |
94 SetItemNum (g, w, s); | |
95 } | |
96 | |
97 public void SetCallback (Callback c) { | |
98 this.callback = c; | |
99 } | |
100 | |
101 public void SetItemNum (int glass, int wood, int sand) { | |
102 this.GlassItem = glass; | |
103 this.WoodItem = wood; | |
104 this.SandItem = sand; | |
105 this.callback (sand, wood, glass); | |
106 print (glass + ", " + wood + ", " + sand); | |
107 } | |
41 } | 108 } |