g1/Assets/PlayerController.cs
2026-01-26 20:59:13 +09:00

32 lines
739 B
C#

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
// 파일 이름이 'PlayerCtrller'와 정확히 일치해야 합니다.
public class PlayerController : MonoBehaviour
{
private Rigidbody playerRigidbody;
public float speed = 8f;
void Start()
{
playerRigidbody = GetComponent<Rigidbody>();
}
void Update()
{
float xInput = Input.GetAxis("Horizontal");
float zInput = Input.GetAxis("Vertical");
float xSpeed = xInput * speed;
float zSpeed = zInput * speed;
Vector3 newVelocity = new Vector3(xSpeed, 0f, zSpeed);
playerRigidbody.linearVelocity = newVelocity;
}
public void Die()
{
gameObject.SetActive(false);
}
}