티스토리 뷰

Unity/수업자료

2차

Kim2558 2018. 5. 11. 02:25
EnemyAttack02 


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
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
 
public class EnemyAttack02 : MonoBehaviour {
 
    public PlayerHealth02 playerHealth;
    public int damage = 10;
    public float attackDelay = 0.5f;
    private float timer = 0;
 
    
    // Update is called once per frame
    void Update () {
        timer -= Time.deltaTime;
    }
 
    
    private void OnCollisionStay(Collision collision)
    {
        if (collision.transform.tag == "Player" && timer < 0 && playerHealth.health >= 0)
        {
            playerHealth.TakeDamage(damage);
            timer = attackDelay;
        }
    }
 
}
 
cs


EnemyMove 

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
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.AI;
 
public class EnemyMove : MonoBehaviour
{
 
    public Transform targetTransform;
    NavMeshAgent nav;
    Animator enemyAnim;
 
    // Use this for initialization
    void Start()
    {
        enemyAnim = GetComponent<Animator>();
        nav = GetComponent<NavMeshAgent>();
    }
 
    // Update is called once per frame
    void Update()
    {
        nav.destination = targetTransform.position;
        bool isRunning = nav.velocity.x != 0 || nav.velocity.z != 0;
        enemyAnim.SetBool("IsRunning", isRunning);
 
    }
}
 
cs

FollowCam 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
 
public class FollowCam : MonoBehaviour {
    public Transform targetTransform;
    public float speed = 10;
    Vector3 offset;
    // Use this for initialization
    void Start () {
        offset = transform.position - targetTransform.position;
    }
    
    // Update is called once per frame
    void Update () {
        transform.position = Vector3.Lerp(transform.position, targetTransform.position + offset, speed * Time.deltaTime);
    }
}
 
cs

PlayerHealth02

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
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
 
public class PlayerHealth02: MonoBehaviour {
 
    public int health = 100;
    public Slider healthSlider;
 
    public Image damageImage;
    public float flashSpeed = 5.0f;
    private Color flashColor = new Color(1000.1f);
 
    private Animator playerAnim;
    
    private bool damaged = false;
    public bool isDead = false;
    public PlayerMove playerMove;
    
    // Use this for initialization
    void Start () {
        playerAnim = GetComponent<Animator>();
    }
    
    // Update is called once per frame
    void Update () {
        healthSlider.value = health;
        if (health <= 0 && !isDead)
        {
            Death();
        }
        if (damaged)
        {
            damageImage.color = flashColor;
        }
        else
        {
            damageImage.color = Color.Lerp(damageImage.color, Color.clear, flashSpeed * Time.deltaTime);
        }
        damaged = false;
    }
 
    public void TakeDamage(int damage)
    {
        damaged = true;
        health -= damage;
    }
 
    void Death()
    {
        isDead = true;
        playerAnim.SetTrigger("Die");
        playerMove.enabled = false;
    }
 
 
}
 
cs


프로젝트 링크 

1차.pptx

https://drive.google.com/open?id=19t_Y8mrkpgYeDKmdRMU4lF1NDe8SX65L

댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
TAG
more
«   2025/01   »
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
글 보관함