g1/Assets/PlayerCtrller.cs
2026-01-26 16:01:19 +09:00

40 lines
961 B
C#

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
// 파일 이름이 'PlayerCtrller'여야 합니다 (띄어쓰기 절대 금지!)
public class PlayerCtrller : MonoBehaviour
{
public Rigidbody playerRigidbody;
public float speed = 8f;
void Start()
{
}
void Update()
{
if (Input.GetKey(KeyCode.UpArrow))
{
playerRigidbody.AddForce(0f, 0f, speed);
}
if (Input.GetKey(KeyCode.DownArrow))
{
playerRigidbody.AddForce(0f, 0f, -speed);
}
if (Input.GetKey(KeyCode.RightArrow))
{
playerRigidbody.AddForce(speed, 0f, 0f);
}
if (Input.GetKey(KeyCode.LeftArrow))
{
playerRigidbody.AddForce(-speed, 0f, 0f);
}
} // <--- Update 함수가 여기서 딱 끝나야 합니다!
// Die 함수는 Update 밖(아래)에 있어야 합니다.
public void Die()
{
gameObject.SetActive(false);
}
}