유니티 심화

절대강좌 유니티 - 총알 이펙트효과

다모아 2023. 8. 21. 10:57

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

public class QuaternionMain : MonoBehaviour
{
    [SerializeField]
    private GameObject wallGo;
    [SerializeField]
    private GameObject bulletGo;
    [SerializeField]
    private GameObject effectPrefab;
    // Update is called once per frame
    void Update()
    {
        if (Input.GetMouseButtonDown(0))
        {
            Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
            Debug.DrawRay(ray.origin, ray.direction * 100f, Color.yellow, 5f);
            RaycastHit hit;
            if(Physics.Raycast(ray, out hit, 100f))
            {
                //맞은 위치에서 법선 벡터방향의 화살표를 5초간 초록색으로 그린다
                DrawArrow.ForDebug(hit.point, hit.normal, 5f, Color.green, ArrowType.Solid);
                Quaternion rot = Quaternion.LookRotation(hit.normal);
                //this.bulletGo.transform.rotation = rot;
                Instantiate(this.effectPrefab, hit.point, rot);
            }
        }        
    }
}