Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
Tags
- Unity
- 파이썬
- UE5
- Unreal Engine 5
- 재귀
- W3Schools
- 기초
- 시작해요 언리얼 2022
- Tutorial
- Programming
- dynamic
- 프로그래밍
- loop
- guide
- DP
- 백준
- Algorithm
- python
- C#
- 오류
- c++
- 문제풀이
- parameter
- String
- Basic
- dfs
- github
- Material
- w3school
- Class
Archives
- Today
- Total
행복한 개구리
Unity 21.04.08.복습 본문
버튼과 애니메이션 연결
ㄴ달리기
ㄴ공격
ㄴ정지상태
카메라 캐릭터에게 고정
UI카메라 생성 및 UI화면에 바인딩

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class MainCamera : MonoBehaviour
{
GameObject hero;
// Start is called before the first frame update
void Start()
{
this.hero = GameObject.Find("Hero");
}
// Update is called once per frame
void Update()
{
this.transform.position = new Vector3(this.hero.transform.position.x + 2, this.hero.transform.position.y+2, this.hero.transform.position.z+3);
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class UIGame : MonoBehaviour
{
public Button btnAttack;
public Button btnMove;
public Button btnIdle;
// Start is called before the first frame update
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class InGame : MonoBehaviour
{
public UIGame uiGame;
public Hero hero;
// Start is called before the first frame update
void Start()
{
this.uiGame.btnAttack.onClick.AddListener(() =>
{
this.hero.Attack();
});
this.uiGame.btnMove.onClick.AddListener(() =>
{
this.hero.Move();
});
this.uiGame.btnIdle.onClick.AddListener(() =>
{
this.hero.Idle();
});
}
// Update is called once per frame
void Update()
{
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Hero : MonoBehaviour
{
Animation anime;
bool isMove;
float moveSpeed = 1.0f;
public void Attack()
{
this.anime.Play("attack_sword_01");
}
public void Move()
{
this.isMove = true;
this.anime.Play("run@loop");
}
public void Idle()
{
this.isMove = false;
this.anime.Play("idle@loop");
}
void Start()
{
this.anime = GetComponent<Animation>();
this.anime.Play("idle@loop");
this.isMove = false;
}
// Update is called once per frame
void Update()
{
if (this.isMove == true)
{
this.transform.Translate(0, 0, moveSpeed * Time.deltaTime);
}
}
}

============================================================================
1. 아직 언팩을 왜 하는지 이해가 안되며 오늘 처음에 empty오브젝트에 hero프리팹을 넣어서 하다가
2. Init을 잘못했는지 오류가 너무 많이나서 일단 프리팹 없이 하는 것을 복습했다.
'Unity > 복습' 카테고리의 다른 글
Unity 21.04.23. 데이터 불러오기 및 저장 복습 (0) | 2021.04.23 |
---|---|
Unity GUI 21.04.22. 복습 (0) | 2021.04.22 |
Unity GUI 21.04.21.복습 - 데이터 및 인벤토리 슬롯 불러오기 (0) | 2021.04.21 |
Unity 3D 21.04.15.복습 (0) | 2021.04.15 |
Unity 3D 21.04.14.복습 (0) | 2021.04.14 |