[유니티] 슈팅이펙트와 함께 발사

NOAH·2021년 7월 10일
0

Unity

목록 보기
17/33

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Shooting : MonoBehaviour
{

    public Camera FPS_camera;

    public GameObject hitEffectPrefab;
    

   public void Fire()
    {
        RaycastHit _hit;
        Ray ray = FPS_camera.ViewportPointToRay(new Vector3(0.5f, 0.5f));
        if(Physics.Raycast(ray, out _hit, 1000))
        {
            Debug.Log(_hit.collider.gameObject.name);
            GameObject hitEffectGameObeject = Instantiate(hitEffectPrefab, _hit.point, Quaternion.identity);
            Destroy(hitEffectGameObeject, 0.5f);

        }

    }
}

0개의 댓글