Ln Go

Grenade 본문

Unity/Quad Action

Grenade

Ln Ro 2021. 6. 4. 02:21
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Grenade : MonoBehaviour
{
    public GameObject meshObj;
    public GameObject effectObj;
    public Rigidbody rigid;


    void Start()
    {
        StartCoroutine(Explosion());   
    }

    IEnumerator Explosion()
    {
        yield return new WaitForSeconds(3f);
        rigid.velocity = Vector3.zero;
        rigid.angularVelocity = Vector3.zero;
        meshObj.SetActive(false);
        effectObj.SetActive(true);

        RaycastHit[] rayHits = 
            Physics.SphereCastAll(transform.position, 15, Vector3.up, 0f, LayerMask.GetMask("Enemy"));
        foreach (RaycastHit hitObj in rayHits)
        {
            hitObj.transform.GetComponent<Enemy>().HitByGrenade(transform.position);
        }
        //ShpereCastAll : 구체 모양의 레이캐스팅 (모든 오브젝트);

        Destroy(gameObject, 5);
    }
}

'Unity > Quad Action' 카테고리의 다른 글

Missile  (0) 2021.06.04
Bullet  (0) 2021.06.04
Weapon  (0) 2021.06.04
BossMissile  (0) 2021.06.04
BossRock  (0) 2021.06.04
Comments