//TODO Add the projectile interface to this class for ALL Ruyo and the test projectiles. private void OnTriggerEnter2D(Collider2D other) { var hit = other.gameObject; if (hit != null) { if ((ignoredLayersMask.value & (1 << hit.layer)) != 0) //Is the detected collider assigned to any of the ignored layers? { return; //If yes - return, ignoring the collision. } } IHittable hitEntity = hit.GetComponentInParent <Player>(); if (hitEntity != null) { if (hitEntity.ChkHit(projectile) && !(projectile.CanPenetrate)) { Destroy(gameObject);//The projectile hit the player and cannot penetrate them - destroy the projectile. return; } return;//The projectile has done no harm to player or can penetrate through them. Let it phase through } //if we got here - the projectile did not hit player at all. probably hit a wall. if (!projectile.CanPenetrate) { Destroy(gameObject); } }
//zadawanie dmg over time musi być w Update - w OnTriggerStay nie działa, jeśli gracz stoi nieruchomo void Update() { if (isPlayerInRange && PlayerInstance != null) { timePassed += Time.deltaTime; if (timePassed > interval) { PlayerInstance.ChkHit(enemyattack); timePassed = 0.0f; } } }
void OnTriggerEnter2D(Collider2D other) { if (other.gameObject.tag == "CharCollisionBody") { var hit = other.gameObject; PlayerInstance = hit.GetComponentInParent <Player>(); if (PlayerInstance != null) { PlayerInstance.ChkHit(enemyattack); } isPlayerInRange = true; } }