플라즈밍
플라즈마 IT
플라즈밍
  • All (163)
    • MindSet (2)
    • Wisdom (8)
    • Book (18)
    • [Web] (6)
      • [Web]Guide (2)
      • [Web]HTML-CSS-JS (1)
      • [Web]ReactJS (0)
      • [Web]NextJS (1)
    • 퀀트주식투자 (4)
      • [리포트]포트폴리오 (4)
    • 자산배분전략 (2)
      • [리포트]자산배분전략 (1)
    • 포트폴리오 (0)
      • 발걸음 (0)
    • 개발 Note (3)
    • TipNote (5)
    • 알고리즘 (27)
      • 백준[BOJ] 오답노트 (27)
      • 백준[BOJ] 강의 정리 노트 (0)
    • etc-posts (18)
      • Unity :: C# 튜토리얼 (18)
    • Web&Know (23)
    • 끄적임 (4)
    • 세상이슈 (0)
    • Youtube 유튜브 (3)
      • Youtube 채널소개 (3)
    • 창업 Know&Idea (1)
    • Web&Dev (4)
    • 프로젝트 (6)
      • Unity5 Project (3)
      • UnrealEngine4 Project (2)
      • Web Page (1)
    • 주가차트-기술적분석 (2)
    • BlockChain (7)
    • SystemDesign (11)

인기 글

최근 글

hELLO · Designed By 정상우.
플라즈밍

플라즈마 IT

etc-posts/Unity :: C# 튜토리얼

[유니티C#][기초] 14. 튜토리얼 SurvivalShooter 정리.3

2018. 7. 8. 18:26
반응형



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
 
2-3 PlayerHealth
using UnityEngine;
//UI관련 사용하려면 반드시 using
using UnityEngine.UI;
using System.Collections;
using UnityEngine.SceneManagement;
 
 
public class PlayerHealth : MonoBehaviour
{
    public int startingHealth = 100;
    public int currentHealth;
    public Slider healthSlider;
    public Image damageImage;
    public AudioClip deathClip;
    public float flashSpeed = 5f;
    public Color flashColour = new Color(1f, 0f, 0f, 0.1f);
 
 
    Animator anim;
    AudioSource playerAudio;
    PlayerMovement playerMovement;
    //PlayerShooting playerShooting;
    bool isDead;
    bool damaged;
 
 
    void Awake ()
    {
        anim = GetComponent <Animator> ();
        playerAudio = GetComponent <AudioSource> ();
        playerMovement = GetComponent <PlayerMovement> ();
        //playerShooting = GetComponentInChildren <PlayerShooting> ();
        currentHealth = startingHealth;
    }
 
 
    void Update ()
    {
        if(damaged)
        {
            damageImage.color = flashColour;
        }
        else
        {
            damageImage.color = Color.Lerp (damageImage.color, Color.clear, flashSpeed * Time.deltaTime);
        }
        damaged = false;
    }
 
 
    public void TakeDamage (int amount)
    {
        damaged = true;
 
        currentHealth -= amount;
 
        healthSlider.value = currentHealth;
 
        playerAudio.Play ();
 
        if(currentHealth <= 0 && !isDead)
        {
            Death ();
        }
    }
 
 
    void Death ()
    {
        isDead = true;
 
        //playerShooting.DisableEffects ();
 
        anim.SetTrigger ("Die");
 
        playerAudio.clip = deathClip;
        playerAudio.Play ();
 
        playerMovement.enabled = false;
        //playerShooting.enabled = false;
    }
 
 
    public void RestartLevel ()
    {
        SceneManager.LoadScene (0);
    }
}
 
Colored by Color Scripter
cs


반응형
저작자표시 (새창열림)

'etc-posts > Unity :: C# 튜토리얼' 카테고리의 다른 글

[유니티C#][기초] 16. 튜토리얼 SurvivalShooter 정리.5  (0) 2018.07.14
[유니티C#][기초] 15. 튜토리얼 SurvivalShooter 정리.4  (0) 2018.07.14
[유니티C#][기초] 13. 튜토리얼 SurvivalShooter 정리.2  (0) 2018.07.08
[유니티C#][기초] 12. 튜토리얼 SurvivalShooter 정리.1  (0) 2018.07.08
[유니티C#][기초] 11. 적에게 체력 부여하기  (0) 2018.07.08
    'etc-posts/Unity :: C# 튜토리얼' 카테고리의 다른 글
    • [유니티C#][기초] 16. 튜토리얼 SurvivalShooter 정리.5
    • [유니티C#][기초] 15. 튜토리얼 SurvivalShooter 정리.4
    • [유니티C#][기초] 13. 튜토리얼 SurvivalShooter 정리.2
    • [유니티C#][기초] 12. 튜토리얼 SurvivalShooter 정리.1
    플라즈밍
    플라즈밍
    퀀트 주식투자 자산배분 데이터분석 정보 공유 프로그래밍,투자 주제의 책 강의 리뷰 노하우 전수

    티스토리툴바