This repository has been archived by the owner on Sep 20, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPlayer.cs
111 lines (82 loc) · 2.86 KB
/
Player.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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
using UnityEngine;
using System.Collections;
public class Player : SpaceShip { //상속자로 인해 SpaceShip에 있는 것은 생략가능
//Transform[] shotPositions; //총알을 발사하는 위치
/* void Awake()
{
//내 자식에 있는 오브젝트를 전부 가져와서 shotPositions에 넣는다.
shotPositions = new Transform[transform.childCount];
for(int i=0; i<transform.childCount; ++i)
{
shotPositions[i] = transform.GetChild(i);
}
InvokeRepeating("Shoot", 1, 1);
} 생략 */
// float speed = 3f; 생략
void Move(Vector2 direction)
{
Vector2 pos = transform.position;
pos += direction * Time.deltaTime * speed;
//Vector2 min = new Vector2(-4, -3);
//Vector2 max = new Vector2(4, 3);
Vector2 min = Camera.main.ViewportToWorldPoint(new Vector2(0, 0));
Vector2 max = Camera.main.ViewportToWorldPoint(new Vector2(1, 1));
pos.x = Mathf.Clamp(pos.x, min.x, max.x);
pos.y = Mathf.Clamp(pos.y, min.y, max.y);
//if (pos.x > 4)
// pos.x = 4;
//if (pos.x > -4)
// pos.x = -4;
transform.position = pos;
}
void Update () {
//입력을 받아온다.
//왼쪽방향이면 -1 오른쪽 방향이면 1
//입력 안하면 0
float x = Input.GetAxisRaw("Horizontal");
float y = Input.GetAxisRaw("Vertical");
Vector2 Direction = new Vector2(x, y);
//print(Direction);
Direction.Normalize(); //어느 방향이던 크기를 1로 만들어줌
Move(Direction);
//if(Input.GetKeyDown(KeyCode.Space))
//{
// Shoot();
//}
}
public int currentHP = 2;
//처음 만났을 때 한번
void OnTriggerEnter2D(Collider2D other)
{
ObjectPool.current.PoolObject(other.gameObject);
--currentHP;
if (currentHP <= 0)
{
Explode();
Destroy(this.gameObject); //부딪힌 적 제거
}
}
// public GameObject BulletPrefab; 생략
/* void Shoot()
{
for (int i = 0; i < transform.childCount; ++i)
{
GameObject Obj = ObjectPool.current.GetObject(BulletPrefab);
Obj.transform.position = shotPositions[i].position;
Obj.transform.rotation = shotPositions[i].rotation;
Obj.SetActive(true);
//GameObject Obj = (GameObject)Instantiate(BulletPrefab, shotPositions[i].position, shotPositions[i].rotation);
//Destroy(Obj, 2f);
}
//Vector3 Pos = transform.position;
//Pos.y += 1;
//GameObject Obj1 = (GameObject)Instantiate(BulletPrefab, Pos, transform.rotation);
//Destroy(Obj1, 3f);
//Quaternion Rot1 = Quaternion.Euler(0, 0, 10); //z축으로 10도 회전한 뒤 발사
//GameObject Obj2 = (GameObject)Instantiate(BulletPrefab, Pos, Rot1);
//Destroy(Obj2, 3f);
//Quaternion Rot2 = Quaternion.Euler(0, 0, -10); //z축으로 -10도 회전한 뒤 발사
//GameObject Obj3 = (GameObject)Instantiate(BulletPrefab, Pos, Rot2);
//Destroy(Obj3, 3f);
} 생략 */
}