1. 코드
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
|
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Hero : MonoBehaviour
{
public GameObject model;
public int hp;
public string heroName;
public bool isImmortal;
public float speed;
// Start is called before the first frame update
void Start()
{
//Debug.Log("Hello world");
Debug.LogFormat("{0}, {1}, {2}, {3}", this.hp, this.heroName, this.isImmortal, this.speed);
//애니메이션 구성(component)가져오기
Animation anim = this.model.GetComponent<Animation>();
//idle 상태
//달리기 모션 실행
anim.Play("run@loop");
}
// Update is called once per frame
void Update()
{
//캐릭터 이동시키기
//속도, 방향, 시간이 필요
Vector3 dir = Vector3.forward;
Vector3 displacement = this.speed * dir * Time.deltaTime;
this.gameObject.transform.Translate(displacement);
}
}
|
2. 실행 결과
-무한정 뛰어감
'C# > 수업내용' 카테고리의 다른 글
2020.05.07. 수업내용 - 지정된 위치에 몬스터와 캐릭터 생성시키기 (0) | 2020.05.08 |
---|---|
2020.05.07. 수업내용 - Unity 버튼, 이동, 애니메이션 실행 (0) | 2020.05.08 |
2020.05.01. 수업내용 - 2차원 배열(캐릭터 이동하기) (0) | 2020.05.01 |
2020.04.29. 수업내용 - 일일 출석 보상(+연속 출석 보상) (0) | 2020.04.30 |
2020.04.29. 수업내용 - 스킨목록 출력하기 (0) | 2020.04.29 |