12.06 드래곤플라이트 구현
C#/실습 2019. 12. 6. 17:16코드:
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
|
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Ship : MonoBehaviour
{
public Transform bulletInitPoint;
public Vector3 targetV;
public GameObject model;
GameObject prefab;
GameObject modelBullet;
// Start is called before the first frame update
void Start()
{
}
public void Attack()
{
StartCoroutine("MakeBulletForward");
StartCoroutine("MakeBulletSide1");
StartCoroutine("MakeBulletSide2");
}
IEnumerator MakeBulletSide1()
{
while (true)
{
GameObject bulletGO = new GameObject("bullet");
bulletGO.transform.position = bulletInitPoint.position;
Bullet bullet = bulletGO.AddComponent<Bullet>();
modelBullet = Instantiate(prefab);
modelBullet.transform.SetParent(bulletGO.transform, false);
modelBullet.transform.localPosition = Vector3.zero;
bullet.MoveSide1();
yield return new WaitForSeconds(1f);
}
}
IEnumerator MakeBulletSide2()
{
while (true)
{
GameObject bulletGO = new GameObject("bullet");
bulletGO.transform.position = bulletInitPoint.position;
Bullet bullet = bulletGO.AddComponent<Bullet>();
var model = Instantiate(prefab);
model.transform.SetParent(bulletGO.transform, false);
model.transform.localPosition = Vector3.zero;
bullet.MoveSide2();
yield return new WaitForSeconds(1f);
}
}
IEnumerator MakeBulletForward()
{
while(true)
{
GameObject bulletGO = new GameObject("bullet");
bulletGO.transform.position = bulletInitPoint.position;
Bullet bullet = bulletGO.AddComponent<Bullet>();
var model = Instantiate(prefab);
model.transform.SetParent(bulletGO.transform, false);
model.transform.localPosition = Vector3.zero;
yield return new WaitForSeconds(1f);
}
}
// Update is called once per frame
void Update()
{
{
if(this.transform.position.x >= -3.5f)
{
}
}
{
if (this.transform.position.x <= 3.5f )
}
{
if ( this.transform.position.y <= 6f)
}
{
if (this.transform.position.y >= -6f )
}
}
}
http://colorscripter.com/info#e" target="_blank" style="color:#4f4f4ftext-decoration:none">Colored by Color Scripter
|
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
|
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Bullet : MonoBehaviour
{
Coroutine coroutineMove;
// Start is called before the first frame update
void Start()
{
}
public void Move()
{
coroutineMove = StartCoroutine("MoveC");
}
public void MoveSide2()
{
StartCoroutine("MoveSideC2");
StartCoroutine("MoveC");
}
IEnumerator MoveSideC2()
{
while (true)
{
var speed = 2;
if (this.transform.position.y >= 6f || this.transform.position.x <= -3.6f || this.transform.position.x >= 3.6f)
{
Destroy(this.gameObject);
}
yield return null;
}
}
public void MoveSide1()
{
StartCoroutine("MoveSideC1");
StartCoroutine("MoveC");
}
IEnumerator MoveSideC1()
{
while (true)
{
var speed = 2;
if (this.transform.position.y >= 6f || this.transform.position.x <= -3.6f || this.transform.position.x >= 3.6f)
{
Destroy(this.gameObject);
}
yield return null;
}
}
IEnumerator MoveC()
{
while (true)
{
var speed = 2;
if (this.transform.position.y >= 6f)
{
Destroy(this.gameObject);
}
yield return null;
}
}
// Update is called once per frame
void Update()
{
}
}
http://colorscripter.com/info#e" target="_blank" style="color:#4f4f4ftext-decoration:none">Colored by Color Scripter
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
|
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class App2 : MonoBehaviour
{
public Ship ship;
public Button btnAttack;
// Start is called before the first frame update
void Start()
{
btnAttack.onClick.AddListener(() =>
{
});
}
// Update is called once per frame
void Update()
{
}
}
http://colorscripter.com/info#e" target="_blank" style="color:#4f4f4ftext-decoration:none">Colored by Color Scripter
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
|
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class BGScroller : MonoBehaviour
{
private MeshRenderer render;
private float offset;
public float speed;
// Start is called before the first frame update
void Start()
{
render = GetComponent<MeshRenderer>();
}
// Update is called once per frame
void Update()
{
offset += Time.deltaTime * speed;
render.material.mainTextureOffset = new Vector2(0, offset);
}
}
http://colorscripter.com/info#e" target="_blank" style="color:#4f4f4ftext-decoration:none">Colored by Color Scripter
|
참조:
'C# > 실습' 카테고리의 다른 글
12.13 캐릭터 선택하기(랜덤포함) (0) | 2019.12.13 |
---|---|
12.09 충돌감지와 sprite활용하기(delegate) (0) | 2019.12.09 |
12.05 유닛 바라보기 (LookAt 메서드 사용X) (1) | 2019.12.05 |
11.29 캐릭터 움직이기 (Coroutine, Update 비교 및 활용) (0) | 2019.11.29 |
11.26 Hero와 Monster의 App에 의한 수동적 싸움 (delegate) (0) | 2019.11.26 |