최대 1 분 소요

픽킹 : 마우스 동작에 의한 이벤 발생

마우스 효과

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

public class boomb : MonoBehaviour
{
    public GameObject _effectBoom;
    void OnMouseDown()
    {
       Debug.Log(gameObject.name + "커서클릭!!");
    }
    
    void OnMouseUp()
    {
        Debug.Log(gameObject.name+"커서 클릭 후 뗌!!");
    } 

    void OnMouseEnter()
    {
        Debug.Log(gameObject.name + "안으로 들어왔어요!");
    }
    void OnMouseExit()
    {
        Debug.Log(gameObject.name + "밖으로 나갔어요!");
    }
}

image

붐 이펙트 추가하기

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

public class boomb : MonoBehaviour
{
    public GameObject _effectBoom;
    void OnMouseDown()
    {
    GameObject go = Instantiate(_effectBoom, transform.position, _effectBoom.transform.rotation);
      Destroy(go, 5);
      Destroy(gameObject);
    }
}
  • 5초 후에 go의 잔여데이터가 사라짐

히트이펙트 추가

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

public class boomb : MonoBehaviour
{
    public int _durationHit = 3;
    public GameObject _effectBoom;
    public GameObject _effectHit;

    void OnMouseDown()
    {
      _durationHit--;
      GameObject go = Instantiate(_effectHit, transform.position, _effectBoom.transform.rotation);
      Destroy(go, 5);
      if (_durationHit <= 0)
        {
          go = Instantiate(_effectBoom, transform.position, _effectBoom.transform.rotation);
          Destroy(go, 5);
          Destroy(gameObject);
        }
    }
    
    void OnMouseUp()
    {
        Debug.Log(gameObject.name+"커서 클릭 후 뗌!!");
    } 

    void OnMouseEnter()
    {
        Debug.Log(gameObject.name + "안으로 들어왔어요!");
    }
    void OnMouseExit()
    {
        Debug.Log(gameObject.name + "밖으로 나갔어요!");
    }
}

  • Onbutton을 이용해서는 물체에대한 이펙트는 가능하나, 특정 위치에서의 이펙트는 불가능

댓글남기기