unity-16: collision이용한 발사체 효과
public GameObject _hitEffectObj;
void OnCollisionEnter(Collision other)
{
if (other.gameObject.CompareTag("CannonBall"))
{
Destroy(other.gameObject, 0.1f);
Instantiate(_hitEffectObj, other.transform.position, _hitEffectObj.transform.rotation);
}
}
CompareTag("태그이름")
으로 태그이름에 해당하는 것만 작동되게 하기- cannonball만 부딪히면 터지게 만듦
- 히트오브젝트라는 게임오브젝트의효과를, 부딪히는 오브젝트의 위치와, wall의 방향으로 생성
- effect효과 넣어주기
벽을 5번 맞추면 터지게 하기
public int _durationHit = 5;
public GameObject _effectdty;
public GameObject _hitEffectObj;
void OnCollisionEnter(Collision other)
{
if (other.gameObject.CompareTag("CannonBall"))
{
Destroy(other.gameObject, 0.1f);
GameObject go = Instantiate(_hitEffectObj, other.transform.position, _hitEffectObj.transform.rotation);
_durationHit--;
Destroy(go, 1);
if (_durationHit <= 0)
{
go = Instantiate(_effectdty, transform.position, _effectdty.transform.rotation);
Destroy(gameObject);
Destroy(go, 1);
}
}
}
투명 원형에 통과할때 효과생기게 하기
public int _durationHit = 10;
public GameObject _effectdty;
public GameObject _hitEffectObj;
void OnCollisionEnter(Collision other)
{
if (other.gameObject.CompareTag("CannonBall"))
{
Destroy(other.gameObject, 0.1f);
GameObject go = Instantiate(_hitEffectObj, other.transform.position, _hitEffectObj.transform.rotation);
_durationHit--;
Destroy(go, 1);
if (_durationHit <= 0)
{
go = Instantiate(_effectdty, transform.position, _effectdty.transform.rotation);
Destroy(gameObject);
Destroy(go, 1);
}
}
}
void OnTriggerEnter(Collider coll)
{
if (coll.CompareTag("CannonBall"))
{
Destroy(coll.gameObject, 0.1f);
GameObject go = Instantiate(_hitEffectObj, coll.transform.position, _hitEffectObj.transform.rotation);
_durationHit--;
Destroy(go, 1);
if (_durationHit <= 0)
{
go = Instantiate(_effectdty, transform.position, _effectdty.transform.rotation);
Destroy(gameObject);
Destroy(go, 1);
}
}
}
-sphere-
// Start is called before the first frame update
public GameObject _effectEnter;
public GameObject _effectExit;
void OnTriggerEnter(Collider col)
{
if (col.CompareTag("CannonBall"))
Instantiate(_effectEnter, col.transform.position, _effectEnter.transform.rotation);
}
void OnTriggerExit(Collider col)
{
if (col.CompareTag("CannonBall"))
Instantiate(_effectExit, col.transform.position, _effectExit.transform.rotation);
}
- sphere만들고, material만들어서 드래그.
- material renderingMode를 transparent로 , Emission에서 color에서 선택하고, color에서 A를 약하게
- cannonball을 istrigger 체크!(벽은 다른물체를 막아야함) -> 벽마저 통과함 → wall에서 istrigger체크된 cannonball을 막아야함 → wall의 script에서 OntriggerEnter로 설정
- sphere script만들고 wall에 넣어줌
- 들어갈때 나갈때 효과 넣어줌
- OntriggerEnter와 OntriggerExit 사용
댓글남기기