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yDguIHguLLguKPguYDguITguKXguLfguYjguK3guJnguJfguLXguYgKICAgICAgICBmbG9hdCBtb3ZlWCA9IElucHV0LkdldEF4aXMoJnF1b3Q7SG9yaXpvbnRhbCZxdW90Oyk7CiAgICAgICAgZmxvYXQgbW92ZVogPSBJbnB1dC5HZXRBeGlzKCZxdW90O1ZlcnRpY2FsJnF1b3Q7KTsKICAgICAgICBWZWN0b3IzIG1vdmUgPSB0cmFuc2Zvcm0ucmlnaHQgKiBtb3ZlWCArIHRyYW5zZm9ybS5mb3J3YXJkICogbW92ZVo7CiAgICAgICAgY29udHJvbGxlci5Nb3ZlKG1vdmUgKiBtb3ZlU3BlZWQgKiBUaW1lLmRlbHRhVGltZSk7CiAgICAgICAgCiAgICAgICAgLy8g4LiB4Liy4Lij4LiB4Lij4Liw4LmC4LiU4LiUCiAgICAgICAgaWYgKElucHV0LkdldEJ1dHRvbkRvd24oJnF1b3Q7SnVtcCZxdW90OykgJmFtcDsmYW1wOyBpc0dyb3VuZGVkKQogICAgICAgIHsKICAgICAgICAgICAgcGxheWVyVmVsb2NpdHkueSArPSBNYXRoZi5TcXJ0KGp1bXBGb3JjZSAqIC0zLjBmICogUGh5c2ljcy5ncmF2aXR5LnkpOwogICAgICAgIH0KICAgICAgICAKICAgICAgICAvLyDguYHguKPguIfguYLguJnguYnguKHguJbguYjguKfguIcKICAgICAgICBwbGF5ZXJWZWxvY2l0eS55ICs9IFBoeXNpY3MuZ3Jhdml0eS55ICogVGltZS5kZWx0YVRpbWU7CiAgICAgICAgY29udHJvbGxlci5Nb3ZlKHBsYXllclZlbG9jaXR5ICogVGltZS5kZWx0YVRpbWUpOwogICAgICAgIAogICAgICAgIC8vIOC4geC4suC4o+C4oeC4reC4h+C4i+C5ieC4suC4oi3guILguKfguLIKICAgICAgICBmbG9hdCBtb3VzZVggPSBJbnB1dC5HZXRBeGlzKCZxdW90O01vdXNlIFgmcXVvdDspICogbW91c2VTZW5zaXRpdml0eTsKICAgICAgICB0cmFuc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gICAgICBTaG9vdCgpOwogICAgICAgIH0KICAgIH0KICAgIAogICAgdm9pZCBTaG9vdCgpCiAgICB7CiAgICAgICAgaWYgKG11enpsZUZsYXNoICE9IG51bGwpCiAgICAgICAgewogICAgICAgICAgICBtdXp6bGVGbGFzaC5QbGF5KCk7CiAgICAgICAgfQogICAgICAgIAogICAgICAgIFJheWNhc3RIaXQgaGl0OwogICAgICAgIGlmIChQaHlzaWNzLlJheWNhc3QoZnBzQ2FtLnRyYW5zZm9ybS5wb3NpdGlvbiwgZnBzQ2FtLnRyYW5zZm9ybS5mb3J3YXJkLCBvdXQgaGl0LCByYW5nZSkpCiAgICAgICAgewogICAgICAgICAgICBUYXJnZXQgdGFyZ2V0ID0gaGl0LnRyYW5zZm9ybS5HZXRDb21wb25lbnQmbHQ7VGFyZ2V0Jmd0OygpOwogICAgICAgICAgICBpZiAodGFyZ2V0ICE9IG51bGwpCiAgICAgICAgICAgIHsKICAgICAgICAgICAgICAgIHRhcmdldC5UYWtlRGFtYWdlKGRhbWFnZSk7CiAgICAgICAgICAgIH0KICAgICAgICB9CiAgICB9Cn0KCi8vIFRhcmdldC5jcwp1c2luZyBVbml0eUVuZ2luZTsKCnB1YmxpYyBjbGFzcyBUYXJnZXQgOiBNb25vQmVoYXZpb3VyCnsKICAgIHB1YmxpYyBmbG9hdCBoZWFsdGggPSAxMDBmOwogICAgCiAgICBwdWJsaWMgdm9pZCBUYWtlRGFtYWdlKGZsb2F0IGFtb3VudCkKICAgIHsKICAgICAgICBoZWFsdGggLT0gYW1vdW50OwogICAgICAgIGlmIChoZWFsdGggJmx0Oz0gMGYpCiAgICAgICAgewogICAgICAgICAgICBEaWUoKTsKICAgICAgICB9CiAgICB9CiAgICAKICAgIHZvaWQgRGllKCkKICAgIHsKICAgICAgICBEZXN0cm95KGdhbWVPYmplY3QpOwogICAgfQp94Lie4Li14LmI
// PlayerController.cs
using UnityEngine;
public class PlayerController : MonoBehaviour
{
public float moveSpeed = 5f;
public float mouseSensitivity = 2f;
public float jumpForce = 5f;
private CharacterController controller;
private Camera playerCamera;
private float verticalRotation = 0f;
private Vector3 playerVelocity;
private bool isGrounded;
void Start()
{
controller = GetComponent<CharacterController>();
playerCamera = Camera.main;
Cursor.lockState = CursorLockMode.Locked;
}
void Update()
{
// ตรวจสอบการชนพื้น
isGrounded = controller.isGrounded;
if (isGrounded && playerVelocity.y < 0)
{
playerVelocity.y = 0f;
}
// การเคลื่อนที่
float moveX = Input.GetAxis("Horizontal");
float moveZ = Input.GetAxis("Vertical");
Vector3 move = transform.right * moveX + transform.forward * moveZ;
controller.Move(move * moveSpeed * Time.deltaTime);
// การกระโดด
if (Input.GetButtonDown("Jump") && isGrounded)
{
playerVelocity.y += Mathf.Sqrt(jumpForce * -3.0f * Physics.gravity.y);
}
// แรงโน้มถ่วง
playerVelocity.y += Physics.gravity.y * Time.deltaTime;
controller.Move(playerVelocity * Time.deltaTime);
// การมองซ้าย-ขวา
float mouseX = Input.GetAxis("Mouse X") * mouseSensitivity;
transform.Rotate(Vector3.up * mouseX);
// การมองขึ้น-ลง
verticalRotation -= Input.GetAxis("Mouse Y") * mouseSensitivity;
verticalRotation = Mathf.Clamp(verticalRotation, -90f, 90f);
playerCamera.transform.localRotation = Quaternion.Euler(verticalRotation, 0f, 0f);
}
}
// WeaponSystem.cs
using UnityEngine;
public class WeaponSystem : MonoBehaviour
{
public float damage = 10f;
public float range = 100f;
public float fireRate = 15f;
public Camera fpsCam;
public ParticleSystem muzzleFlash;
private float nextTimeToFire = 0f;
void Update()
{
if (Input.GetButton("Fire1") && Time.time >= nextTimeToFire)
{
nextTimeToFire = Time.time + 1f/fireRate;
Shoot();
}
}
void Shoot()
{
if (muzzleFlash != null)
{
muzzleFlash.Play();
}
RaycastHit hit;
if (Physics.Raycast(fpsCam.transform.position, fpsCam.transform.forward, out hit, range))
{
Target target = hit.transform.GetComponent<Target>();
if (target != null)
{
target.TakeDamage(damage);
}
}
}
}
// Target.cs
using UnityEngine;
public class Target : MonoBehaviour
{
public float health = 100f;
public void TakeDamage(float amount)
{
health -= amount;
if (health <= 0f)
{
Die();
}
}
void Die()
{
Destroy(gameObject);
}
}พี่