C#/수업내용
2020-05-07 [unity]
NexTin
2020. 5. 7. 13:08
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
|
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class APP : MonoBehaviour
{
public GameObject model;
public Button button;
private Animation anim;
private bool isbtnClicked; // 버튼 클릭 했는지 안했는지
private bool isAttack; //공격 했는지 안했는지
private float elapsedtime;
private float totalframe;
private float attactime;
// Start is called before the first frame update
void Start()
{
this.anim = this.model.GetComponent<Animation>();
var state = anim["attack_sword_01"];
//this.attackframe =
//q버튼이 눌럿다면 시간 누적
Button btn = this.button.GetComponent<Button>();
btn.onClick.AddListener(TaskOnClick);
}
void TaskOnClick()
{
Debug.Log("버튼 클릭 했습니다.");
this.isbtnClicked = true;
anim.Play("attack_sword_01");
this.isAttack = true;
Debug.Log("공격 애니메이션 시작");
}
// Update is called once per frame
void Update()
{
if (this.isAttack == true) // 공격 버튼 눌렀을때
{
if (this.isbtnClicked == true)
{
this.elapsedtime += Time.deltaTime;
if (this.elapsedtime >= this.attactime) //누적시간이 어택타임을 넘기면 펄스
{
Debug.Log("타격");
if (this.elapsedtime >= this.totalframe)
{
this.isAttack = false;
this.isbtnClicked = false;
Debug.Log("모션 종료");
}
}
}
}
http://colorscripter.com/info#e" target="_blank" style="color:#e5e5e5text-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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
|
using System.Collections;
using System.Collections.Generic;
using Unity.Collections.LowLevel.Unsafe;
using UnityEditor;
using UnityEngine;
using UnityEngine.UI;
public class APP : MonoBehaviour
{
public GameObject model;
public GameObject target;
public Button move;
public Button attack;
private Animation anim;
private Animation targetanim;
public float speed;
private bool isMove;
private bool isAttack;
private float distance;
private float totalFrames;
private float attakTime;
private float elapsedTimeAttack; // 공격시간
private float
// Start is called before the first frame update
void Start()
{
this.anim = model.GetComponent<Animation>();
this.targetanim = target.GetComponent<Animation>();
var btn = move.GetComponent<Button>();
btn.onClick.AddListener(() => isMove = true);
var btn2 = attack.GetComponent<Button>();
btn2.onClick.AddListener(() => isAttack = true);
//float
}
private void Attack()
{
this.anim.Play("attack_sword_01");
this.targetanim.Play("Anim_Damage");
this.anim.Play("idle@loop");
this.targetanim.Play("Anim_Idle");
}
// Update is called once per frame
void Update()
{
if(isMove == true)
{
Vector3 dir = Vector3.forward;
this.model.transform.Translate(this.speed * dir * Time.deltaTime);
this.anim.Play("run@loop");
this.distance = Vector3.Distance(model.transform.position, target.transform.position);
Debug.Log(distance);
if (distance <= 0.9f)
{
this.isMove = false;
Vector3 monsterfront = this.target.transform.position + Vector3.back;
this.model.transform.position = monsterfront;
this.anim.Play("idle@loop");
}
}
if(isAttack == true)
{
this.Attack();
}
}
}
|
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
|
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Hero : MonoBehaviour
{
private GameObject model;
// Start is called before the first frame update
void Start()
{
}
public void Init(GameObject model)
{
this.model = model;
this.model.transform.SetParent(this.transform);
}
// Update is called once per frame
void Update()
{
}
}
|
cs |