-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMe.cs
90 lines (69 loc) · 1.99 KB
/
Me.cs
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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Me : Unit {
protected bool hiding; // ユニットが画面外にいるか
protected Vector3 mePostion; // 自分の初期位置
public Color color = new Color(1.0f, 1.0f, 1.0f, 1.0f);
// Use this for initialization
protected void Start () {
hiding = false;
rb = GetComponent<Rigidbody2D>();
StartCoroutine ("PlayerAttack");
mePostion = transform.position;
// 元の画像の赤色のデータのみで表示される。
this.GetComponent<SpriteRenderer>().color = color;
}
// Update is called once per frame
protected void Update () {
this.GetComponent<SpriteRenderer>().color = color;
PlayerMove ();
if (!gameObject.GetComponentInChildren<Renderer> ().isVisible) {
hiding = true;
} else {
hiding = false;
}
}
/**********************************************************
*
* プレイヤーの攻撃
*
* ********************************************************/
IEnumerator PlayerAttack(){
while (true) {
if (Input.GetKey(KeyCode.K)) {
Shot (transform);
// sound
AudioSource audioSource = gameObject.GetComponent<AudioSource>();
audioSource.PlayOneShot(audioSource.clip);
}
yield return new WaitForSeconds (shotDelay);
}
}
/**********************************************************
*
* プレイヤーの移動
*
* ********************************************************/
/// <summary>
/// キーを取得して、プレイヤーを動かす
/// </summary>
protected void PlayerMove(){
if (Input.GetKey (KeyCode.Space)) {
InitPosition ();
}
float x = Input.GetAxisRaw ("Horizontal");
float y = Input.GetAxisRaw ("Vertical");
MeMove (x, y);
}
/// <summary>
/// Mes the move.
/// </summary>
/// <param name="x">The x coordinate.</param>
/// <param name="y">The y coordinate.</param>
protected virtual void MeMove(float x, float y){
}
private void InitPosition (){
transform.position = mePostion;
}
}