private void OnTriggerEnter2D(Collider2D collider) { if (collider.GetComponent <AreaCamera>() == null && collider.CompareTag("Water") == false && collider.GetComponent <Enemy3>() == null && collider.GetComponent <Enemy4>() == null) // Adição { Debug.Log("Bullet hit " + collider.name); Enemy1 enemy1 = collider.GetComponent <Enemy1>(); Enemy2 enemy2 = collider.GetComponent <Enemy2>(); Boss boss = collider.GetComponent <Boss>(); Player player = collider.GetComponent <Player>(); if (enemy1 != null) // É um inimigo { enemy1.TakeDamage(bulletDamage); } else if (enemy2 != null) { enemy2.TakeDamage(bulletDamage); } else if (boss != null) { boss.TakeDamage(bulletDamage); } else if (player != null) { player.TakeDamage(bulletDamage); } Destroy(gameObject); Instantiate(impactEffect, transform.position, transform.rotation); } }
private void OnTriggerEnter2D(Collider2D collision) { Enemy enemy = collision.GetComponent <Enemy>(); Enemy1 enemy1 = collision.GetComponent <Enemy1>(); Enemy2 enemy2 = collision.GetComponent <Enemy2>(); Enemyboss enemyboss = collision.GetComponent <Enemyboss>(); if (enemy != null) { enemy.TakeDamage(20); } else if (enemy1 != null) { enemy1.TakeDamage(20); } else if (enemy2 != null) { enemy2.TakeDamage(20); } else if (enemyboss != null) { enemyboss.TakeDamage(20); } GameObject destroyffect = Instantiate(impactEffect, transform.position, Quaternion.identity); Destroy(destroyffect, 0.2f); Destroy(gameObject); }
private void OnTriggerExit2D(Collider2D hitInfo) { Enemy1 enemy = hitInfo.GetComponent <Enemy1>(); if (enemy != null) { enemy.TakeDamage(damage); } Destroy(gameObject); }
private void OnTriggerEnter2D(Collider2D hitInfo) { //Debug.Log(hitInfo.name); Enemy1 enemy = hitInfo.GetComponent<Enemy1>(); if (enemy != null) { enemy.TakeDamage(damage); Instantiate(hitEnemySparksEffect, transform.position, transform.rotation); //Destroy(player.GetComponent<throwhook>().curHook); //player.GetComponent<throwhook>().ropeActive = false; Invoke("resetRope", 0.25f); Vector2 directionOfObj = (Vector2)transform.position - (Vector2)hitInfo.GetComponent<Transform>().position; hitInfo.GetComponent<Rigidbody2D>().AddForce(directionOfObj.normalized * -enemy.knockbackFromWep); } Instantiate(sparksEffect, transform.position, transform.rotation); if (hitInfo.gameObject.tag == "Can Interact" && hitInfo.gameObject.GetComponent<Rigidbody2D>().mass < 10) { //Destroy(player.GetComponent<throwhook>().curHook); //player.GetComponent<throwhook>().ropeActive = false; Invoke("resetRope", 0.05f); GameObject hookedItem = hitInfo.gameObject; Vector2 directionOfObj = (Vector2)transform.position - (Vector2)hookedItem.transform.position; if (player.GetComponent<PlayerMovement>().crouch) // crouch to pull object to player { //hookedItem.GetComponent<Transform>().position = Vector2.MoveTowards((Vector2)hookedItem.transform.position, (Vector2)transform.position, 10); hookedItem.GetComponent<Rigidbody2D>().AddForce(directionOfObj.normalized * hookPullForce); } else // else push object away from player { hookedItem.GetComponent<Rigidbody2D>().AddForce(directionOfObj.normalized * -hookPushForce); //hookedItem.GetComponent<Transform>().position = Vector2.MoveTowards((Vector2)hookedItem.transform.position, (Vector2)transform.position, 10); } } if (hitInfo.gameObject.tag == "Collectibles" || hitInfo.gameObject.tag == "Enemy" || hitInfo.gameObject.tag == "Bat") { Invoke("resetRope", 0.1f); } if (hitInfo.gameObject.tag == "Can Fall") { /* transform.position = Vector2.MoveTowards(transform.position, hitInfo.gameObject.GetComponent<Transform>().position, 10); Debug.Log(transform.position);*/ Invoke("resetRope", hitInfo.gameObject.GetComponent<FallingRock>().timeb4Fall + 0.1f); } }
// Update is called once per frame void OnTriggerEnter2D(Collider2D hitInfo) { Enemy1 enemy1 = hitInfo.GetComponent <Enemy1>(); // If an enemy is hit if (enemy1 != null) { enemy1.TakeDamage(BulletDamage); } Instantiate(ImpactEffect, transform.position, transform.rotation); Destroy(gameObject); }
// Update is called once per frame private void OnTriggerEnter2D(Collider2D collision) { Enemy1 enemy = collision.GetComponent <Enemy1>(); if (enemy != null) { enemy.TakeDamage(damage); } if (collision.gameObject.tag == "suit") { } else { Destroy(gameObject); } }
void Update() { if (Input.GetButtonDown("Fire1") && Time.time > nextFire) { nextFire = Time.time + fireRate; StartCoroutine(ShotTraceFX()); Vector3 rayOrigin = fpsCam.ViewportToWorldPoint(new Vector3(0.5f, 0.5f, 0)); RaycastHit hit; laserLine.SetPosition(0, bezzel.position); if (Physics.Raycast(rayOrigin, fpsCam.transform.forward, out hit)) { laserLine.SetPosition(1, hit.point); Enemy1 target1 = hit.transform.GetComponent <Enemy1>(); if (target1 != null) { target1.TakeDamage(DMG); } Enemy2 target2 = hit.transform.GetComponent <Enemy2>(); if (target2 != null) { target2.TakeDamage2(DMG); } Enemy3 target3 = hit.transform.GetComponent <Enemy3>(); if (target3 != null) { target3.TakeDamage3(DMG); } if (hit.rigidbody != null) { hit.rigidbody.AddForce(-hit.normal * 1555); } } else { laserLine.SetPosition(1, rayOrigin + (fpsCam.transform.forward * 100)); } } }
private void OnTriggerEnter2D(Collider2D collider) { if (collider.GetComponent <AreaCamera>() == null && collider.GetComponent <Player>() == null) // Não é uma câmera nem o Player { Enemy1 enemy1 = collider.GetComponent <Enemy1>(); Enemy2 enemy2 = collider.GetComponent <Enemy2>(); Enemy3 enemy3 = collider.GetComponent <Enemy3>(); Enemy4 enemy4 = collider.GetComponent <Enemy4>(); Boss boss = collider.GetComponent <Boss>(); if (enemy1 != null) // É um inimigo { enemy1.TakeDamage(bulletDamage); } else if (enemy2 != null) { enemy2.TakeDamage(bulletDamage); } else if (enemy3 != null) { enemy3.TakeDamage(bulletDamage); } else if (enemy4 != null) { enemy4.TakeDamage(bulletDamage); } else if (boss != null) { boss.TakeDamage(bulletDamage); } Destroy(gameObject); Instantiate(impactEffect, transform.position, transform.rotation); } }