12.09 충돌감지와 sprite활용하기(delegate)
C#/실습 2019. 12. 9. 17:25코드:
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
|
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using System;
public class App : MonoBehaviour
{
public Button btnShoot;
public Transform bulletInitPoint;
private GameObject bulletPrefab;
private Sprite explosionsprite;
// Start is called before the first frame update
void Start()
{
this.LoadResources();
this.btnShoot.onClick.AddListener(() =>
{
Debug.Log("발사!");
this.Shoot();
});
}
private void LoadResources()
{
}
private void Shoot()
{
GameObject bulletModel = Instantiate(bulletPrefab);
Bullet bullet = bulletModel.AddComponent<Bullet>();
bulletModel.transform.position = this.bulletInitPoint.position;
bullet.ShootCoroutine = bullet.ShootImple();
StartCoroutine(bullet.ShootCoroutine);
{
StopCoroutine(bullet.ShootCoroutine);
GameObject explosionGO = new GameObject("explosion");
explosionGO.transform.position = bullet.transform.position;
SpriteRenderer spriteRenderer = explosionGO.AddComponent<SpriteRenderer>();
spriteRenderer.sprite = Instantiate(explosionsprite);
Animator animator = explosionGO.AddComponent<Animator>();
animator.runtimeAnimatorController =
(RuntimeAnimatorController)RuntimeAnimatorController.Instantiate(
explosion explosion = explosionGO.AddComponent<explosion>();
Destroy(bullet.gameObject);
};
}
// 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 explosion : MonoBehaviour
{
public void whenExplode()
{
Destroy(this.transform.root.gameObject);
}
// Start is called before the first frame update
void Start()
{
}
// 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
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
|
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System;
public class Bullet : MonoBehaviour
{
public Action del;
public IEnumerator ShootCoroutine;
// Start is called before the first frame update
void Start()
{
}
//private void OnCollisionEnter(Collision collision)
//{
// App.del();
//}
private void OnTriggerEnter(Collider other)
{
{
this.del();
}
}
public IEnumerator ShootImple()
{
while (true)
{
this.transform.position += vc * 1 * Time.deltaTime;
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
|
참조:
Sprite 파일
https://www.pngguru.com/free-transparent-background-png-clipart-zceay
Sprite GameMaker: Studio Animation 2D computer graphics, explosion sprite transparent background PNG clipart | PNGGuru
PNG Clipart Information Dimensions 960x384px File size 113.87KB MIME type Image/png dominant color orange Resize PNG Clipart online resize by width resize by height
www.pngguru.com
스프라이트 애니메이션
유니티 - 스프라이트 시트(sprite sheet) 사용하기, 스프라이트 애니메이션
유니티에서 sprite sheet 사용하기, sprite 애니메이션 1)스프라이트 시트(sprite sheet)는 2D 애니메이션...
blog.naver.com
코드에서 애니메이션 바꾸기
https://playground10.tistory.com/95
[유니티] 코드에서 애니메이션 바꾸기
프리팹은 하나이고 애니메이션만 계속 코드에서 동적으로 바꾸고 싶을 때 아래와 같이 해주면 됩니다. 1. 먼저 해당 프리팹에 animator 컴포넌트를 추가해줍니다. (기존에 프리팹을 Player라고 만들었고 스크립트..
playground10.tistory.com
'C# > 실습' 카테고리의 다른 글
12.16 UI 버튼 만들기 (0) | 2019.12.16 |
---|---|
12.13 캐릭터 선택하기(랜덤포함) (0) | 2019.12.13 |
12.06 드래곤플라이트 구현 (0) | 2019.12.06 |
12.05 유닛 바라보기 (LookAt 메서드 사용X) (1) | 2019.12.05 |
11.29 캐릭터 움직이기 (Coroutine, Update 비교 및 활용) (0) | 2019.11.29 |