총 발사, 총알 발사 궤적 효과 만들기 - Trail Renderer
-bullet에 collider, rigidbody 추가. usegravity는 체크를 풀어준다.
-FirePos는 발사 위치를 나타낸다.
새 메터리얼을 만들고 mobile/particles/additive로 변경해 particel texture에 이미지를 추가한다. 이 메터리얼을 trail render에 메터리얼 속성에 넣어준다.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class FireController : MonoBehaviour
{
[SerializeField]private GameObject bullet;
[SerializeField]private Transform firePos;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
if(Input.GetMouseButtonDown(0))
{
Fire();
}
}
private void Fire()
{
Instantiate(bullet,firePos.position,firePos.rotation);//총알 프리팹의 인스턴스 생성
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class RemoveBullet : MonoBehaviour
{
private void OnCollisionEnter(Collision collision)
{
Debug.Log(collision);
if (collision.collider.CompareTag("Bullet"))
{
Destroy(collision.gameObject); //bullet
}
//if (collision.collider.tag == "Bullet")
//{
// Destroy(collision.gameObject); //bullet
//}
}
}
'유니티 심화' 카테고리의 다른 글
오디오, 코루틴으로 총구 효과 (0) | 2023.08.22 |
---|---|
파티클 활용, 폭발, random texture,폭발력 적용(AddExplosionForce) (0) | 2023.08.21 |
카메라 이동 연습 2(draw gizmos, 선형 보간과 구면 선형 보간) (0) | 2023.08.18 |
Player 이동 연습2(정규화 벡터) (0) | 2023.08.18 |
카메라 위치 조정 & Zoom In/Out (0) | 2023.08.17 |