void Update() { //status if (this.droneHealth < 0 || this.selfDestruct) { while (debrisAmount < maxDebris) { for (debrisAmount = 0; debrisAmount < maxDebris; debrisAmount++) { debri[debrisAmount] = ModAPI.CreatePhysicalObject("Debris", debrisComp.debrisSprites[UnityEngine.Random.Range(0, debrisComp.debrisSprites.Length)]); debri[debrisAmount].transform.position = transform.position; randomDirection = UnityEngine.Random.Range(-5, 5); debri[debrisAmount].GetComponent <PhysicalBehaviour>().rigidbody.AddForce(new Vector2(randomDirection, randomDirection) * debrisForce); } } ModAPI.CreateParticleEffect("Explosion", transform.position); Destroy(gameObject); selfDestruct = false; } }
// Update is called once per frame void Update() { armExtractPos = new Vector2(transform.position.x, transform.position.y - .2f); armRetractPos = new Vector2(transform.position.x, transform.position.y); if (readyToDropBomb) { bombPreview.SetActive(true); bomberArms.transform.position = armExtractPos; timeTillDrop += Time.deltaTime; if (timeTillDrop > 2) { GameObject bomb = ModAPI.CreatePhysicalObject("BOMB", ModAPI.LoadSprite("Sprites/Bomb.png")); bomb.transform.position = bombPreview.transform.position; if (!bomb.GetComponent <BombComponent>()) { bomb.AddComponent <BombComponent>(); } cooldown = true; cooldownTime = 5; readyToDropBomb = false; bombPreview.SetActive(false); } else { if (timeTillDrop > 1.9) { GetComponent <DroneModBehaviour>().overwriteHover = true; } } } else { bomberArms.transform.position = armRetractPos; timeTillDrop = 0; } if (cooldown) { cooldownTime -= Time.deltaTime; } if (cooldownTime <= 0) { cooldown = false; } Collider2D aliveObjectInRadius = Physics2D.OverlapCircle(transform.position, 10f, LayerMask.GetMask("Objects")); if (aliveObjectInRadius.gameObject.GetComponent <LimbBehaviour>()) { targetObjLoc = aliveObjectInRadius.transform.position - transform.position; if (!cooldown) { readyToDropBomb = true; targetObjLoc.Normalize(); GetComponent <PhysicalBehaviour>().rigidbody.velocity = new Vector2(targetObjLoc.x * movSpeed, GetComponent <PhysicalBehaviour>().rigidbody.velocity.y); } else { GetComponent <PhysicalBehaviour>().rigidbody.velocity = new Vector2(-targetObjLoc.x * movSpeed / 2, GetComponent <PhysicalBehaviour>().rigidbody.velocity.y); } } else { if (cooldown) { if (GetComponent <PhysicalBehaviour>().rigidbody.velocity.magnitude > .3) { GetComponent <PhysicalBehaviour>().rigidbody.velocity = new Vector2(GetComponent <PhysicalBehaviour>().rigidbody.velocity.x / cooldownTime, GetComponent <PhysicalBehaviour>().rigidbody.velocity.y); } } readyToDropBomb = false; } }