using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Move : MonoBehaviour
{
// Time.deltaTime : Update() 메서드가 한번 호출되고 다시 호출되기까지 걸린시간을 의미
public float speed = 5;
float h; // 좌우방향키 입력값
float v; // 상하방향키 입력값
Vector2 dir;
void Start()
{
}
// 고성능pc - Time.deltaTime 값이 매우 작은 값이 된다
// 저성능pc - Time.deltaTime 값이 매우 커지게 된다
// Time.deltaTime을 이용해서 성능차이가 있는 기기일지라도 같은 시간에 같은 거리를 움직이게
void Update() // 1초당 60번 프레임이 호출(=반복실행), 60fps
{
h = Input.GetAxisRaw("Horizontal"); // +1, -1, 0
v = Input.GetAxisRaw("Vertical"); // +1, -1, 0
dir = (Vector2.right * h) + (Vector2.up * v);
transform.Translate(dir * speed * Time.deltaTime);
if (h != 0)
{
transform.localScale = new Vector2(h, 1);
}
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class CameraController : MonoBehaviour
{
// 카메라가 플레이어(cat)를 따라간다.-수직이동(y축)
// 카메라가 씬에서 cat을 찾는다.
GameObject player; // 목표게임오브젝트를 찾아서 player변수에 넣기
Vector3 playerPos;
void Start()
{
player = GameObject.Find("cat");
}
void Update()
{
// cat의 위치값을 넣는다(추적)
playerPos = player.transform.position; // cat의 위치값 저장
transform.position = new Vector3(transform.position.x, playerPos.y, transform.position.z);
}
}
'----------고1---------- > 게임엔진' 카테고리의 다른 글
[고1 게임엔진] 10 - (1) (0) | 2023.10.11 |
---|---|
[고1 게임엔진] 09 - (6) (0) | 2023.09.25 |
[고1 게임엔진] 09 - (4) (0) | 2023.09.18 |
[고1 게임엔진] 09 - (3) (0) | 2023.09.13 |
[고1 게임엔진] 09 - (2) (3) | 2023.09.11 |