플라즈밍
플라즈마 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#][기초] 15. 튜토리얼 SurvivalShooter 정리.4

2018. 7. 14. 16:22
반응형



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
 
2-4 PlayerShooting
 
using UnityEngine;
 
public class PlayerShooting : MonoBehaviour
{
    public int damagePerShot = 20;
    public float timeBetweenBullets = 0.15f;
    public float range = 100f;
 
 
    float timer;
    Ray shootRay = new Ray();
    RaycastHit shootHit;
    int shootableMask;
    ParticleSystem gunParticles;
    LineRenderer gunLine;
    AudioSource gunAudio;
    Light gunLight;
    float effectsDisplayTime = 0.2f;
 
 
    void Awake ()
    {
        shootableMask = LayerMask.GetMask ("Shootable");
        gunParticles = GetComponent<ParticleSystem> ();
        gunLine = GetComponent <LineRenderer> ();
        gunAudio = GetComponent<AudioSource> ();
        gunLight = GetComponent<Light> ();
    }
 
 
    void Update ()
    {
        timer += Time.deltaTime;
 
        //Time.timescale-> 플레이 시간 조정 -> 일시정지 / 슬로우 무션 / 정상속도 / 2배 속도 가능
        if(Input.GetButton ("Fire1") && timer >= timeBetweenBullets && Time.timeScale != 0)
        {
            Shoot ();
        }
 
        if(timer >= timeBetweenBullets * effectsDisplayTime)
        {
            DisableEffects ();
        }
    }
 
 
    public void DisableEffects ()
    {
        gunLine.enabled = false;
        gunLight.enabled = false;
    }
 
 
    void Shoot ()
    {
        timer = 0f;
 
        gunAudio.Play ();
 
        gunLight.enabled = true;
 
        gunParticles.Stop ();
        gunParticles.Play ();
 
        gunLine.enabled = true;
        gunLine.SetPosition (0, transform.position);
 
        shootRay.origin = transform.position;
        shootRay.direction = transform.forward;
 
        if(Physics.Raycast (shootRay, out shootHit, range, shootableMask))
        {
            EnemyHealth enemyHealth = shootHit.collider.GetComponent <EnemyHealth> ();
            if(enemyHealth != null)
            {
                enemyHealth.TakeDamage (damagePerShot, shootHit.point);
            }
            gunLine.SetPosition (1, shootHit.point);
        }
        else
        {
            gunLine.SetPosition (1, shootRay.origin + shootRay.direction * range);
        }
    }
}
 
Colored by Color Scripter
cs


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

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

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

    티스토리툴바