// Basically once we figure out all of the object in the game we can see if the bullet hits one of those things, the bullet breaks void OnTriggerEnter2D(Collider2D collision) { // Debug.Log("Hit "+collision.tag+" for " + damage); if (collision.gameObject.tag == "Player Bullet") { // Debug.Log("Player Bullet"); Destroy(gameObject); } if (collision.gameObject.tag == "GrabAble") { // Debug.Log("Block"); GrappleObjectScript obj = collision.gameObject.GetComponent <GrappleObjectScript>(); obj.DamageObject(damage); Destroy(gameObject); } if (collision.gameObject.tag == "GrabAbleReflector") { // Debug.Log("Block"); ReflectorScript obj = collision.gameObject.GetComponent <ReflectorScript>(); obj.DamageObject(damage); Destroy(gameObject); GameObject bullet = Instantiate(playerBullet, collision.transform.position + collision.transform.forward * 10, collision.transform.rotation); //EnemyBulletBehavior eb = bullet.GetComponent<EnemyBulletBehavior>(); //eb.SetDamage(this.damage); // Debug.Log("After setting damage, damage is "+eb.GetDamage()); Rigidbody2D bulletBody = bullet.GetComponent <Rigidbody2D>(); bulletBody.AddForce(bullet.transform.up * -1000); //Destroy(gameObject); } if (collision.gameObject.tag == "Player") { player = collision.gameObject.GetComponent <PlayerController>(); if (!player.GetIsInvincible()) { PlayerController player = collision.gameObject.GetComponent <PlayerController>(); player.damagePlayer(damage); Destroy(gameObject); } } if (collision.gameObject.tag == "HorizWall" || collision.gameObject.tag == "VerticalWall") { // Debug.Log("Wall"); Destroy(gameObject); } }
// Update is called once per frame void Update() { if (!isHolding) { if (Input.GetMouseButtonDown(1) && timer > 70) { grabMaster.getClosest(grabMaster.grabs); isHolding = true; } timer++; } else if (isHolding && Input.GetMouseButtonDown(1)) { child = GameObject.Find("Grabbed"); rigid = child.GetComponent <Rigidbody2D>(); if (child.tag == "GrabAble") { grappleReg = child.GetComponent <GrappleObjectScript>(); grappleReg.Shot(true); rigid.isKinematic = false; } else if (child.tag == "GrabAbleReflector") { reflector = child.GetComponent <ReflectorScript>(); reflector.Shot(true); rigid.isKinematic = false; } currentTimeMulti = GameStateManager.GetTimeMulti(); rigid.AddForce(child.transform.up * 0.3f * currentTimeMulti); grabMaster.removeChild(); isHolding = false; timer = 0; } if (grabMaster.transform.childCount == 0) { isHolding = false; } //Debug.Log("ChildCount:" + grabMaster.transform.childCount); }