<죽어라돌덩이>

Unity/수업내용 2019. 4. 12. 01:40




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 App : MonoBehaviour
{
    public GameObject heroGo;
    public GameObject monsterGo;
    
    // Start is called before the first frame update
    void Start()
    {
        var hero = this.heroGo.GetComponent<Character>();
        var monster = this.monsterGo.GetComponent<Character>();
 
        hero.Init(new Vector3(101));
        monster.Init(new Vector3(505));
 
 
        hero.Move(monster);
    }
 
    // Update is called once per frame
    void Update()
    {
        
    }
}
 
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
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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
 
public class Character : MonoBehaviour
{
    private float speed = 1f;
    private float lange = 0.7f;
    private int hp = 10;
    private Vector3 targetPosition;
    private Vector3 attackTargetPosition;
    private float moveDis;
 
    private Character target;
 
    private bool isMoveComplete = false;
    private bool isMoveStart = false;
 
    private bool isAttackStart = false;
 
    private Animation anim;
 
    private float timer = 0.0f;
    private float waitingTime = 1.5f;
    // Start is called before the first frame update
    void Start()
    {
        this.anim = this.gameObject.GetComponent<Animation>();
    }
 
    public void Init(Vector3 initPosition)
    {
        this.gameObject.transform.position = initPosition;
    }
 
    public void Move(Character target)
    {
        this.target = target;
        this.targetPosition = target.gameObject.GetComponent<Character>().transform.position;
        this.moveDis = Vector3.Distance(this.targetPosition, this.gameObject.GetComponent<Character>().transform.position);
        this.isMoveStart = true;
    }
 
    public void MoveStart()
    {
        anim.Play("run@loop");
        var normVec = (this.targetPosition - this.gameObject.GetComponent<Character>().transform.position).normalized;
 
        if (isMoveComplete == false)
        {
            if (moveDis > this.lange)
            {
                //계속앞으로 이동
                moveDis -= speed * Time.deltaTime;
                this.gameObject.GetComponent<Character>().transform.position += this.speed * normVec * Time.deltaTime;
            }
            else
            {
                isMoveStart = false;
                isMoveComplete = true;
                isAttackStart = true;
                anim.Play("idle@loop");
            }
        }
    }
 
    public void AttackStart()
    {
        anim.Play("attack_sword_01");
        var normVec = (this.targetPosition - this.gameObject.GetComponent<Character>().transform.position).normalized;
        
        this.target.gameObject.GetComponent<Animation>().Play("Anim_Damage");
        this.hp--;
        
        Debug.Log(this.hp);
 
        if (this.hp <= -1)
        {
            Debug.Log("으앙쥬금");
            anim.Play("idle@loop");
            this.isAttackStart = false;
        }
    }
 
    // Update is called once per frame
    void Update()
    {
        if(this.hp<=-1)
        {
            this.target.gameObject.GetComponent<Animation>().Play("Anim_Death");
            this.hp = 0;
        }
        if (isMoveStart == true)
        {
            this.MoveStart();
        }
        this.timer += Time.deltaTime;
        if(this.timer>waitingTime)
        {
            if (isAttackStart == true)
            {
                this.AttackStart();
            }
            this.timer = 0;
        }
    }
}
 
cs


//고개돌리기, 타이밍싱크, 공격방식 바꾸면서 때리기

'Unity > 수업내용' 카테고리의 다른 글

(1)BGLoop  (0) 2019.05.01
LayerMask  (0) 2019.05.01
자습서1(WASD이동, 마우스 포인트 Look, 라인렌더링  (0) 2019.04.30
<캐릭터 조작>화면 터치, WASD, 조이스틱  (0) 2019.04.25
HUDTest  (0) 2019.04.25
: