public void SpawnFireball(float startX, float startY, float endX, float endY, bool missed) { Vector2 start = new Vector2(startX, startY); GameObject go = Resources.Load <GameObject>("prefabs/CatapultBullet"); CatapultBullet bullet = GameObject.Instantiate(go, start, Quaternion.identity).GetComponent <CatapultBullet>(); bullet.startPos = start; bullet.endPos = new Vector2(endX, endY); bullet.missed = missed; }
public override IEnumerator resolve() { if (shipA == null || (shipB == null && missedNode == null) || !shipA.CanFire) { if (shipA == null) { Debug.Log("attacker is null for catapult resolution"); } if (shipA != null && !shipA.CanFire) { Debug.Log(shipA.name + " canfire is false"); } if (shipB == null) { Debug.Log(shipA.name + " catapult target was null"); } yield break; } Vector2 focusPos; shipA.SetIconAttack(); if (missedNode == null) { shipB.SetIconTarget(); focusPos = (shipA.Position + shipB.Position) / 2; } else { focusPos = (shipA.Position + (Vector3)missedNode.getRealPos()) / 2; } yield return(PhaseManager.SyncFocus(focusPos)); yield return(new WaitForSeconds(SpeedManager.CombatDelay)); //GameManager.main.LaunchSound(); Sounds.main.playClip(Sounds.main.Launch); yield return(new WaitForSeconds(SpeedManager.CatapultLaunchDelay)); GameObject go = Resources.Load <GameObject>("prefabs/CatapultBullet"); CatapultBullet bullet = GameObject.Instantiate(go, shipA.transform.position, Quaternion.identity).GetComponent <CatapultBullet>(); if (missedNode == null) { bullet.endPos = shipB.Position; if (shipA.getNode() == shipB.getNode()) { bullet.sameNode = true; } } else { if (missedNode == shipA.getNode()) { bullet.endPos = shipA.Position + new Vector3(Random.Range(-0.4f, 0.4f), Random.Range(-0.4f, 0.4f)); } else { bullet.endPos = missedNode.getRealPos(); } bullet.missed = true; } bullet.startPos = shipA.transform.position; if (PhotonNetwork.IsMasterClient) { PhotonView.Get(GameManager.main).RPC("SpawnFireball", RpcTarget.Others, bullet.startPos.x, bullet.startPos.y, bullet.endPos.x, bullet.endPos.y, bullet.missed); } while (!bullet.impacted) { yield return(null); } if (missedNode == null) { //shipB.life -= damageToB; shipB.TakeDamage(damageToB); } if (missedNode == null && shipB.life == 0) { yield return(new WaitForSeconds(SpeedManager.CombatPostDelay * 2)); } else { yield return(new WaitForSeconds(SpeedManager.CombatPostDelay)); } shipA.DisableIcon(); shipA.CanFire = false; if (missedNode == null) { shipB.DisableIcon(); } resolved = true; yield return(null); }