Skip to content

Latest commit

ย 

History

History
191 lines (157 loc) ยท 8.24 KB

File metadata and controls

191 lines (157 loc) ยท 8.24 KB

๊ต๋ž€์šฉ ํด๋ก  ๋งŒ๋“ค๊ธฐ

  • ์ˆ ๋ž˜๋ฅผ ํ—ท๊ฐˆ๋ฆฌ๊ฒŒ ํ•˜๋Š” ํด๋ก ๋“ค์„ ๋งŒ๋“ค์–ด์ฃผ์ž.
  • ํ”Œ๋ ˆ์ด์–ด์™€ ๊ฐ™์€ ๋ชจ์–‘์˜ Capsule์„ ํ•˜๋‚˜ ๋งŒ๋“ค์–ด์ฃผ๊ณ  ์ด๋ฆ„์„ Clone์ด๋ผ ํ•ด์ฃผ์ž.

  • Clone์— rigidbody, PhotonView, PhotonTransformView, NavMeshAgent๋ฅผ ๋„ฃ์–ด์ฃผ์ž.
  • Rigidbody์—์„œ xyz๊ณ ์ •์— xyz์ถ•ํšŒ์ „๋„ ๊ณ ์ •์œผ๋กœ ํ•ด์ฃผ์ž.
  • NavMeshAgent๋Š” ํด๋ก ๋“ค์ด ์ˆœ์ฐฐํ• ๋•Œ ๋„์›€์„ ์ค€๋‹ค.

  • ClonePatrol์Šคํฌ๋ฆฝํŠธ๋ฅผ ๋งŒ๋“ค์–ด์ค€๋‹ค.

  • SpawnManager์—์„œ ์Šคํฐํฌ์ธํŠธ๋กœ ์ผ๋˜ ์œ„์น˜๊ฐ’์„ ์ˆœ์ฐฐํฌ์ธํŠธ๋กœ ํ•ด์„œ ๊ณ„์† ์ˆœ์ฐฐํ•˜๊ฒŒ ์ฝ”๋“œ๋ฅผ ์ž‘์„ฑํ•ด์ฃผ์ž.

  • Clone ํƒœ๊ทธ๋ฅผ ๋ถ™์—ฌ์ฃผ๊ณ  ํ”„๋ฆฌํŽฉํ™” ์‹œ์ผœ์ค€๋‹ค.

---------------------------------------------- ]

  • Game Scene์—์„œ ์ง€ํ˜•์œผ๋กœ ์“ธ ๋ฌผ์ฒด๋“ค์„ ๋‹ค ์„ ํƒํ•ด์ค€๋‹ค.

  • Navigation์—์„œ object์™€ Bake ์„ค์ •์„ ๋‹คํ•ด์ฃผ๊ณ  Bake ๋ฒ„ํŠผ์„ ๋ˆŒ๋Ÿฌ์ฃผ์ž.

  • ์ด์ œ NavMeshAgent๊ฐ€ ๊ฑธ์–ด๋‹ค๋‹ ์ˆ˜ ์žˆ๋Š” ๋ฒ”์œ„๊ฐ€ ์ƒ‰๊น”๋กœ ํ‘œํ˜„๋œ๋‹ค.

  • Game Scene์— Clone๋“ค์„ ์—ฌ๋Ÿฌ๊ฐœ ์˜ฌ๋ ค๋†“๊ณ  ์‹คํ–‰ํ•ด๋ณด๋ฉด ์ˆœ์ฐฐ์„ ์ž˜ํ•˜๋Š”๊ฑธ ๋ณผ ์ˆ˜ ์žˆ๋‹ค.

  • Single Shot Gun ์Šคํฌ๋ฆฝํŠธ๋ฅผ ์ˆ˜์ •ํ•ด์ฃผ์ž.
  • Clone๋“ค์€ ์ด๋งž์œผ๋ฉด ๋ฐ”๋กœ ์‚ฌ๋ผ์ง€๋„๋ก ์ฝ”๋“œ๋ฅผ ์ˆ˜์ •ํ•ด์ฃผ์ž.
  • ๋˜ํ•œ ์ˆ ๋ž˜๊ฐ€ ํด๋ก ์ธ์ฒ™ํ•˜๋Š” ์‚ฌ๋žŒ์„ ๋งž์ถ”๋ฉด ์ฒด๋ ฅ์ด ํšŒ๋ณต๋˜๋„๋ก ์ฝ”๋“œ๋ฅผ ์ˆ˜์ •ํ•ด์ฃผ์ž.


  • PlayerController ํ”„๋ฆฌํŽฉ์—์žˆ๋Š” Rifle๊ณผ Pistol์— shooter๋ฅผ ์ถ”๊ฐ€ํ•ด์ฃผ์ž.
  • PlayerController์— Playerํƒœ๊ทธ๋ฅผ ์ถ”๊ฐ€ํ•ด์ฃผ์ž.

  • ์‹คํ–‰ํ•ด๋ณด๋ฉด ์ด์— ๋งž์œผ๋ฉด Clone๋“ค์€ ์‚ฌ๋ผ์ง€๊ณ  Player๋ฅผ ๋งž์ถ”๋ฉด ์ฒด๋ ฅ์ด ํšŒ๋ณต๋˜๋Š”๊ฑธ ๋ณผ ์ˆ˜ ์žˆ๋‹ค.

using Photon.Pun;
using Photon.Realtime;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.AI;

public class ClonePatrol : MonoBehaviour
{
    private NavMeshAgent agent;
    //์ˆœ์ฐฐ์„ ์œ„ํ•œ ๋„ค๋น„๊ฒŒ์ด์…˜ ๋ฉ”์‰ฌ ์—์ด์ „ํŠธ
    PhotonView PV;
    //์œ„์น˜ ๋™๊ธฐํ™”์šค PV
    void Awake()
    {
        PV = GetComponent<PhotonView>();
        agent = GetComponent<NavMeshAgent>();

    }
    void Start()
    {
        agent.autoBraking = false;
        //์ˆœ์ฐฐ ๊ณ„์†ํ•จ
        GotoNextPoint();
    }
    void GotoNextPoint()
    {
        Transform Patrolpoint = SpawnManager.Instance.GetSpawnpoint();
        //์Šคํฐ ํฌ์ธํŠธ๋กœ ์ผ๋˜ ์œ„์น˜๋“ค์„ ์ˆœ์ฐฐ ํฌ์ธํŠธ๋กœ ์”€
        agent.destination = Patrolpoint.position;
        //๋„ค๋น„๊ฒŒ์ด์…˜ ๋‹ค์Œ ๋ชฉ์ ์ง€๋ฅผ ๋žœ๋ค ์ˆœ์ฐฐํฌ์ธํŠธ๋กœ
    }
    void Update()
    {
        if (!agent.pathPending && agent.remainingDistance < 0.5f)
            GotoNextPoint();
        //๊ทผ์ฒ˜์—๊ฐ€๋ฉด ๋‹ค์Œ ๋ชฉ์ ์ง€๋กœ
    }
}
  • Clone Patrol ์Šคํฌ๋ฆฝํŠธ์˜ ์ „๋ฌธ์ด๋‹ค.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Photon.Pun;

public class SingleShotGun : Gun
//Gun์œผ๋กœ๋ถ€ํ„ฐ ์ •๋ณด๋ฐ›๊ธฐ
{
    [SerializeField] Camera cam;
    PhotonView PV;
    public GameObject shooter;
    void Awake()
    {
        PV = GetComponent<PhotonView>();  
    }
    public override void Use()
    {
        Debug.Log("using gun " + itemInfo.itemName);
        Shoot();
    }

    void Shoot()
    {
        Ray ray = cam.ViewportPointToRay(new Vector3(0.5f, 0.5f));
        //์นด๋ฉ”๋ผ๋กœ๋ถ€ํ„ฐ ๋ ˆ์ด์ € ๋ฐœ์‚ฌ
        ray.origin = cam.transform.position;
        //๋ฐœ์‚ฌ์ง€์  ์นด๋ฉ”๋ผ๋กœ๋ถ€ํ„ฐ
        if (Physics.Raycast(ray, out RaycastHit hit))
        {
            hit.collider.gameObject.GetComponent<IDamageable>()?.TakeDamage(((GunInfo)itemInfo).damage);
            //๋ ˆ์ด์ €์— ๋งž์€ ๋ฌผ์ฒด๊ฐ€ ๋ฐ๋ฏธ์ง€๋ฅผ ์ž…์„ ์ˆ˜ ์žˆ๋Š” ๋ฌผ์ฒด์ธ๊ฐ€? ๋งž๋‹ค๋ฉด ์•„์ดํ…œ ์ •๋ณด์— ๋งž๋Š” ๋ฐ๋ฏธ์ง€ ๋ฐ›๊ธฐ
            if (hit.transform.tag == "Player")
            {
                shooter.GetComponent<PlayerController>()?.TakeDamage(-30);
                //์Œ์ˆ˜๊ฐ’์˜ ๋ฐ๋ฏธ์ง€๋ฅผ ์ž…์œผ๋‹ˆ๊นŒ ์ฒด๋ ฅ ํšŒ๋ณต์ด๋‹ค.
            }
            if (hit.transform.tag == "Clone")
            {
                Destroy(hit.transform.gameObject);
            }
            PV.RPC("RPC_Shoot", RpcTarget.All, hit.point,hit.normal );
            //๋งž์ถ”๋ฉด ์ƒ๋Œ€๋ฐฉํ•œํ…Œ ๋งž์•˜๋‹ค๊ณ  ์•Œ๋ ค์ฃผ๊ธฐ
        }
    }

    [PunRPC]//Pun Remote Procedure Call์˜ ์•ฝ์ž๋กœ์จ ์›๊ฒฉ์ œ์–ด๋ฅผ ํ†ตํ•ด ํ•จ์ˆ˜๋ฅผ ์‹คํ–‰์‹œํ‚ค๋Š” ๊ธฐ๋Šฅ์ด๋‹ค.  
    void RPC_Shoot(Vector3 hitPosition,Vector3 hitNoraml) 
    {//hitNormal์€ ๋งž๋Š” ๋ฉด์ด ํ–ฅํ•˜๋Š” ๋ฐฉํ–ฅ์ด๋‹ค.  
        Collider[] colliders = Physics.OverlapSphere(hitPosition, 0.3f);
        //0.3f ๋ฐ˜๊ฒฝ๋‚ด์— collider๋“ค์„ ๊ฒ€์ถœํ•œ๋‹ค. 
        if (colliders.Length != 0)//์ฝœ๋ผ์ด๋”๊ฐ€ ์กด์žฌํ•œ๋‹ค๋ฉด
        {
            GameObject bulletImpactObj=Instantiate(bulletImpactPrefab, hitPosition + hitNoraml * 0.001f, Quaternion.LookRotation(hitNoraml, Vector3.up) * bulletImpactPrefab.transform.rotation);
            //hitPosition+hitNormal*0.001f๋ฅผ ํ•ด์ฃผ๋ฉด ์ด์•Œ ์ž๊ตญ์ด ๋Œ€์ƒํ‘œ๋ฉด ๋ณด๋‹ค ์•„์ฃผ ์‚ด์ง ์œ„์—์žˆ๊ฒŒ๋˜์„œ ๊ฒน์ณ๋ณด์ด์ง€ ์•Š๋Š”๋‹ค. 
            Destroy(bulletImpactObj, 10f);
            //์ด์•Œ ์ž๊ตญ์€ 10์ดˆํ›„์—๋Š” ์‚ฌ๋ผ์ง„๋‹ค.  
            bulletImpactObj.transform.SetParent(colliders[0].transform);
            //์ฃผ๋ณ€์— ์žˆ๋Š” ์ฝœ๋ผ์ด๋”๋ฅผ ๋ถ€๋ชจ๋กœ ์„ค์ •ํ•œ๋‹ค.  
            //๋ถ€๋ชจ๊ฐ€ ์‚ฌ๋ผ์ง€๋ฉด ์ž์‹๋ฌผ์ฒด๋“ค๋„ ๋‹ค ์‚ฌ๋ผ์ง€๋ฏ€๋กœ ์ด์•Œ์ž๊ตญ๋งŒ ๋‘ฅ๋‘ฅ๋– ๋‹ค๋‹ˆ๋Š”๊ฑธ ํ•ด๊ฒฐ ํ•  ์ˆ˜ ์žˆ๋‹ค.  
        }
    }
        
}
  • Single Shot Gun ์Šคํฌ๋ฆฝํŠธ์˜ ์ „๋ฌธ์ด๋‹ค.