Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions CameraController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class CameraController : MonoBehaviour
{
public GameObject player;

public float turnSpeed = 0.5f; // ���콺 ȸ�� �ӵ�
private float xRotate = 0.0f; // ���� ����� X�� ȸ������ ���� ����

// Start is called before the first frame update
void Start()
{

}

// Update is called once per frame
void Update()
{
float yRotateSize = Input.GetAxis("Mouse X") * turnSpeed;
float yRotate = transform.eulerAngles.y + yRotateSize;

float xRotateSize = -Input.GetAxis("Mouse Y") * turnSpeed;
// ���Ʒ� ȸ������ ���������� -45�� ~ 80���� ���� (-45:�ϴù���, 60:�ٴڹ���)
// Clamp �� ���� ������ �����ϴ� �Լ�
xRotate = Mathf.Clamp(xRotate + xRotateSize, -45, 60);

// ī�޶� ȸ������ ī�޶� �ݿ�(X, Y�ุ ȸ��)
transform.eulerAngles = new Vector3(xRotate, yRotate, 0);

//���� ���� �ٶ󺸱�
Vector3 dir = player.transform.position - transform.position;
dir.y = 0;
Quaternion rot = Quaternion.LookRotation(dir.normalized);
transform.rotation = rot;
}
}
43 changes: 43 additions & 0 deletions CapsuleController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class CapsuleController : MonoBehaviour, IDamageable
{
float health = 100f;
bool dead = false;
public virtual bool ApplyDamage(DamageMessage damageMessage)
{
if (dead) return false; //���� ���¸� ������ �� ����

health -= damageMessage.amount;

if (health <= 0) Die_effect(gameObject);

return true;
}

void Die()
{
gameObject.SetActive(false);
dead = true;
}

void Die_effect(GameObject capsule)
{
gameObject.GetComponent<ParticleSystem>().Play();
Invoke("Die", 0.5f);
}

// Start is called before the first frame update
void Start()
{

}

// Update is called once per frame
void Update()
{

}
}
47 changes: 47 additions & 0 deletions CapsuleSpawner.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class CapsuleSpawner : MonoBehaviour
{
public GameObject spawner;
BoxCollider spawnerCollider;

private void Awake()
{
spawnerCollider = spawner.GetComponent<BoxCollider>();
//�ݶ��̴� ���� �������� ĸ�� �����ϱ�
}

Vector3 RandomPosition()
{
Vector3 originPosition =spawner.transform.position;
// �ݶ��̴��� ����� �������� bound.size ���
float range_X = spawnerCollider.bounds.size.x;
float range_Z = spawnerCollider.bounds.size.z;

range_X = Random.Range((range_X / 2) * -1, range_X / 2);
range_Z = Random.Range((range_Z / 2) * -1, range_Z / 2);
float range_Y = Random.Range(2f, 4f);
Vector3 RandomPostion = new Vector3(range_X, range_Y, range_Z);

Vector3 spawnPosition = originPosition + RandomPostion;
return spawnPosition;
}
public GameObject capsule;
private void Start()
{
StartCoroutine(RandomRespawn_Coroutine()); //3�� �������� ĸ�� ����
}

IEnumerator RandomRespawn_Coroutine()
{
while (true)
{
yield return new WaitForSeconds(3f);

Instantiate(capsule, RandomPosition(), Quaternion.identity);

}
}
}
10 changes: 10 additions & 0 deletions DamageMessage.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
using UnityEngine;

public struct DamageMessage
{
public GameObject damager;
public float amount;

public Vector3 hitPoint;
public Vector3 hitNormal;
}
9 changes: 9 additions & 0 deletions IDamageable.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public interface IDamageable
{
//���� ���ϴ� �ֵ����� �ϰ������� DamageMessage �ֱ�
bool ApplyDamage(DamageMessage damageMessage);
}
62 changes: 62 additions & 0 deletions PlayerController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class PlayerController : MonoBehaviour
{// ���콺�� ���� ���� �ٲٰ� bulletGenerator���� ����

public GameObject bulletPrefab;
public int weight; //�ӵ� ����ġ

RaycastHit hit;
public int turnSpeed;
Quaternion dr;

public float moveSpeed; //�׶��忡���� ������
private float xRotate = 0.0f; //���� �ٶ󺸱�

PlayerInput playerInput; //������Ʈ�� start���� �Ҵ��Ű��

public void Move(Vector3 dir)
{
transform.Translate(dir);
}
// Start is called before the first frame update
void Start()
{
playerInput = GetComponent<PlayerInput>();
}

private void FixedUpdate()
{
//���� ���� �ֱ⿡ ���� ������

float move_X = playerInput.move_x;
float move_Z = playerInput.move_z;
Vector3 move = new Vector3(move_X, 0, move_Z);

Move(transform.TransformDirection(move) * Time.deltaTime*10);


}

// Update is called once per frame
void Update()
{


if (Input.GetMouseButton(1)) //������ ��ư���� ���� �ٲٱ�
{
Physics.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition), out hit); //hit�� �浹���� ����
Vector3 click = hit.point;

dr = Quaternion.LookRotation((click - transform.position).normalized); //Ŭ���� �������� ȸ���ض�
transform.rotation = Quaternion.Slerp(transform.rotation, dr, turnSpeed * Time.deltaTime); //���� �ð��� ȸ��

}

}


}

25 changes: 25 additions & 0 deletions PlayerInput.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class PlayerInput : MonoBehaviour
{
public string moveX = "Horizontal";
public string moveZ = "Vertical";
public string mouseX = "Mouse X";

// Start is called before the first frame update
//�ܺο��� �� �б⸸ ����
public float move_x { get; private set; }
public float move_z { get; private set; }
public float mouse_x { get; private set; } //�ϴ� ���ܵ���


// Update is called once per frame
void Update()
{
move_x = Input.GetAxis(moveX);
move_z = Input.GetAxis(moveZ);
mouse_x = Input.GetAxis(mouseX);
}
}
78 changes: 78 additions & 0 deletions Shoot.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Shoot : MonoBehaviour
{
public GameObject Bullet;
public Transform FirePos; //�ѱ�

//�Ѿ� �߻�
public Camera mainCamera;
RaycastHit hit;

// Start is called before the first frame update
void Start()
{

}

// Update is called once per frame
void FixedUpdate()
{
if (Input.GetMouseButtonDown(0))
{
Ray ray = mainCamera.ScreenPointToRay(Input.mousePosition);

//�浹�� ������� ��������� �Ѿ�
Instantiate(Bullet, FirePos.transform.position, FirePos.transform.rotation);

if (Physics.Raycast(ray, out hit,100f))
{
transform.LookAt(hit.point); //Ŭ���� ���� �ٶ󺸱�

// �浹�� �������κ��� IDamageable ������Ʈ�� �������� �õ�
var target =
hit.collider.GetComponent<IDamageable>();

// �������� ���� IDamageable ������Ʈ�� �������µ� �����ߴٸ�
if (target != null)
{
DamageMessage damageMessage;

damageMessage.damager = this.gameObject;
damageMessage.amount = 25f;
damageMessage.hitPoint = hit.point;
damageMessage.hitNormal = hit.normal;

// ������ OnDamage �Լ��� ������Ѽ� ���濡�� ������ �ֱ�
target.ApplyDamage(damageMessage);

//�Ѿ� �̵�: �ٵ� �Ѿ��� �� ����(�ӵ� 1f�� �ص� ��������)
Bullet.transform.position = Vector3.MoveTowards(Bullet.transform.position, hit.point, 1f);
}
}
//�浹 ���ص� �߰��� ��
else
{
Bullet.transform.position = Vector3.MoveTowards(Bullet.transform.position, ray.direction * 100f, 1f);
}

if (Mathf.Abs(Bullet.transform.position.x) >= 100 || Mathf.Abs(Bullet.transform.position.z) >= 100)
{
Bullet.SetActive(false);
Destroy(Bullet);
}

}
}
private void OnTriggerEnter(Collider other) //�浹�ϸ� �������
{
if (other.tag == "Enemy")
{
Bullet.GetComponent<SphereCollider>().enabled = false;
Bullet.SetActive(false);
Destroy(Bullet);
}
}
}