33 lines
790 B
C#
33 lines
790 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()
|
|
{
|
|
FindObjectOfType<GameManager>().EndGame();
|
|
gameObject.SetActive(false);
|
|
}
|
|
} |