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 |
Tags
- 오류
- 문제풀이
- 시작해요 언리얼 2022
- dynamic
- Programming
- guide
- Algorithm
- C#
- github
- DP
- 기초
- 프로그래밍
- UE5
- dfs
- Unity
- c++
- Basic
- Unreal Engine 5
- 파이썬
- W3Schools
- 백준
- Class
- Material
- 재귀
- Tutorial
- parameter
- python
- w3school
- String
- loop
Archives
- Today
- Total
행복한 개구리
Unity 21.04.06.수업내용 본문
프리팹(PreFab)은 게임오브젝트가 'file화' 된 것.
Rigidbody : 물리적 작용
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
public class ClearDirector : MonoBehaviour
{
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
if (Input.GetMouseButtonDown(0))
{
SceneManager.LoadScene("GameScene");
}
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class CameraController : MonoBehaviour
{
GameObject cat;
// Start is called before the first frame update
void Start()
{
this.cat = GameObject.Find("cat");
}
// Update is called once per frame
void Update()
{
Vector3 playerPos = this.cat.transform.position;
transform.position = new Vector3(transform.position.x, playerPos.y, transform.position.z);
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
public class PlayerController : MonoBehaviour
{
Animator animator;
Rigidbody2D rigid2D;
public float jumpForce;
public float walkForce;
public float maxWalkSpeed;
// Start is called before the first frame update
void Start()
{
this.rigid2D = this.GetComponent<Rigidbody2D>();
this.animator = GetComponent<Animator>();
}
// Update is called once per frame
void Update()
{
if (Input.GetKeyDown(KeyCode.Space))
{
this.rigid2D.AddForce(transform.up * this.jumpForce);
}
var dir = 0;
if (Input.GetKey(KeyCode.LeftArrow))
{
dir = -1;
}
if (Input.GetKey(KeyCode.RightArrow))
{
dir = 1;
}
float speedx = Mathf.Abs(this.rigid2D.velocity.x);
if(speedx < 2.0f)
{
this.rigid2D.AddForce(this.transform.right * dir * walkForce);
}
if(dir != 0)
{
transform.localScale = new Vector3(dir, 1, 1);
}
this.animator.speed = speedx / 2.0f;
}
private void OnTriggerEnter2D(Collider2D collision)
{
Debug.Log("WIN !");
SceneManager.LoadScene("ClearScene");
}
}
============================================================================
'Unity > 수업내용' 카테고리의 다른 글
Unity 21.04.14.수업내용 (0) | 2021.04.14 |
---|---|
Unity 21.04.09.수업내용 (0) | 2021.04.09 |
Unity 21.04.08.수업내용 (0) | 2021.04.08 |
Unity 21.04.07.수업내용 (0) | 2021.04.07 |
Unity 21.04.05.수업내용 (0) | 2021.04.05 |