GameManager.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
|
using System.Collections;
using UnityEngine;
public class GameManager : MonoBehaviour
{
private static GameManager _instance;
public static GameManager Instance
{
get
{
if (_instance == null)
{
_instance = FindObjectOfType<GameManager>();
}
return _instance;
}
}
public GameObject poop;
public Transform objbox;
void Start()
{
StartCoroutine(CreatepoopRoutine());
}
IEnumerator CreatepoopRoutine()
{
while (true)
{
CreatePoop();
yield return new WaitForSeconds(0.3f);
}
}
private void CreatePoop()
{
Vector3 pos = Camera.main.ViewportToWorldPoint(new Vector3(UnityEngine.Random.Range(0.0f, 1.0f), 1.1f, 5.0f));
GameObject obj = Instantiate(poop, pos, Quaternion.identity);
obj.transform.parent = objbox.transform;
}
}
http://colorscripter.com/info#e" target="_blank" style="color:#4f4f4ftext-decoration:none">Colored by Color Scripter
|
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
|
using UnityEngine;
public class Player : MonoBehaviour
{
private Rigidbody2D rigidbody;
private SpriteRenderer renderer;
private float speed = 3;
void Start()
{
rigidbody = GetComponent<Rigidbody2D>();
renderer = GetComponent<SpriteRenderer>();
}
void FixedUpdate()
{
PlayerMove();
ScreenChk();
}
private void PlayerMove()
{
float horizontal = Input.GetAxis("Horizontal");
if (horizontal < 0)
{
}
else if (horizontal > 0)
{
}
rigidbody.velocity = new Vector2(horizontal * speed, rigidbody.velocity.y);
}
private void ScreenChk()
{
if (worlpos.x < 0.05f) worlpos.x = 0.05f;
if (worlpos.x > 0.95f) worlpos.x = 0.95f;
}
}
http://colorscripter.com/info#e" target="_blank" style="color:#4f4f4ftext-decoration:none">Colored by Color Scripter
|
poop.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
|
using UnityEngine;
public class poop : MonoBehaviour {
private Rigidbody2D rigidbody;
void Start () {
rigidbody = GetComponent<Rigidbody2D>();
}
private void OnCollisionEnter2D(Collision2D collision)
{
{
Destroy(gameObject);
}
}
}
http://colorscripter.com/info#e" target="_blank" style="color:#4f4f4ftext-decoration:none">Colored by Color Scripter
|
'유니티2D' 카테고리의 다른 글
초간단 유니티로 엔드리스 러너 만들기! (0) | 2020.01.16 |
---|---|
유니티 인벤토리 만들기! 그 첫번째! UI (0) | 2019.11.23 |
튜토리얼을 모아 만들어 본 게임(?) (0) | 2019.11.09 |
[유니티] 조이스틱 만들기! (0) | 2019.10.27 |
유니티로 TelePort를 구현해보자! (0) | 2019.09.13 |