void OnCollisionEnter(Collision collision) { if (isServer) { if (collision.gameObject.tag == "ship") { /*dfcontroller dfcontrol = collision.gameObject.GetComponent<dfcontroller>(); * if (dfcontrol != null) * { * dfcontrol.setDamage(damage); * }*/ ShipScript shipControl = collision.gameObject.GetComponent <ShipScript>(); if (shipControl != null) { Debug.Log("damage"); shipControl.setDamage(damage); } else { Debug.Log("not damage"); } } Debug.Log(collision.gameObject); GameObject explosion = Resources.Load("ExplosionShim") as GameObject; GameObject expl = (GameObject)Instantiate(explosion, transform.position, transform.rotation); NetworkServer.Spawn(expl); Destroy(this.gameObject); } }
private void HandleExplosion() { Collider2D[] hitColliders = Physics2D.OverlapCircleAll(transform.position, blastRadius); foreach (Collider2D col in hitColliders) { Vector3 pos = col.transform.position; Vector2 impulse = pos - transform.position; impulse /= impulse.magnitude; impulse *= blastForce; float percent = (blastRadius - Vector3.Distance(pos, transform.position)) / blastRadius; if (col.tag == "Ship") { ShipScript ship = col.GetComponent <ShipScript>(); ship.TakeHit(impulse * percent, pos); ship.ApplyDamage(m_damage * percent, m_shieldPenetration); } else if (col.tag == "Asteroid" || col.tag == "Satellite" || col.tag == "sAsteroid") { //Rigidbody2D roidRb = col.GetComponent<Rigidbody2D>(); //roidRb.AddForce( impulse * percent, ForceMode2D.Impulse ); Satellite sat = col.GetComponent <Satellite>(); sat.ApplyDamage(m_damage * percent, Vector2.zero, pos, false); } } }
private void NextShipClicked() { if (!shipScript.OnGameBoard()) { shipScript.FlashColor(Color.red); } else { if (shipIndex <= ships.Length - 2) { shipIndex++; shipScript = ships[shipIndex].GetComponent <ShipScript>(); shipScript.FlashColor(Color.yellow); } else { rotateBtn.gameObject.SetActive(false); nextBtn.gameObject.SetActive(false); woodDock.gameObject.SetActive(false); topText.text = "Awaiting coordinates, Admiral.."; setupComplete = true; //hideships for (int i = 0; i < ships.Length; i++) { ships[i].SetActive(false); } } } }
private void Setup() { SubSystemScript _subSysScr = gameObject.GetComponent <SubSystemScript> (); gridPos = _subSysScr.GridPos; ship = LevelManager.Instance.Ships [_subSysScr.GridPos.Z].GetComponent <ShipScript> (); GameObject _sysObj = transform.parent.parent.GetChild(1).gameObject; if (_sysObj.transform.childCount > 0) { if (_sysObj.transform.GetChild(0).GetComponent <WeaponSysScr>() != null) { weaponSysScr = _sysObj.transform.GetChild(0).GetComponent <WeaponSysScr>(); isWeaponTerminal = true; } else if (_sysObj.transform.GetChild(0).GetComponent <TeleporterScr>() != null) { teleporterScr = _sysObj.transform.GetChild(0).GetComponent <TeleporterScr>(); isTeleporterTerminal = true; } else { Debug.LogError("/*weaponSysScr*/ someSysScr == null"); } } }
private void Setup() { sysScr = GetComponent <SystemScript>(); gridPos = sysScr.GridPos; playerID = gridPos.Z; ship = LevelManager.Instance.Ships[playerID].GetComponent <ShipScript>(); pwrMngr = ship.GetComponent <ShipPowerMngr>(); hScr = sysScr.GetOriginObj().GetComponent <HealthScript>(); //ship.IncreaseEvasionChance (componentCapacity); pwrMngr.PowerSetup(systemType, powerReq); originTeleporterScr = GetOriginTelScr(); if (this == originTeleporterScr) { isOrigin = true; } originTeleporterScr.fullPwrReq += powerReq; if (isOrigin) { pwrMngr.AddToSysScrList(systemType, sysScr); } RoomScript _room = transform.parent.parent.GetChild(0).GetChild(0).GetComponent <RoomScript>(); room = _room.GetOriginObj().GetComponent <RoomScript>(); }
private void DestroyObject() { if (totalArmor <= 0) { switch (parent) { case Parent.Rocket: { RocketScript rocket = gameObject.GetComponent <RocketScript>(); if (rocket != null && rocket.allowTriggers) { rocket.CustomDestroy(); } } break; case Parent.Asteroid: { Asteroid asteroid = gameObject.GetComponent <Asteroid>(); if (asteroid != null) { asteroid.CustomDestroy(); } } break; case Parent.Ship: { ShipScript ship = gameObject.GetComponent <ShipScript>(); if (ship != null) { ship.CustomDestroy(); } } break; } } }
private void Setup() { sysScr = GetComponent <SystemScript>(); gridPos = sysScr.GridPos; playerID = gridPos.Z; ship = LevelManager.Instance.Ships[playerID].GetComponent <ShipScript>(); pwrMngr = ship.GetComponent <ShipPowerMngr>(); hScr = sysScr.GetOriginObj().GetComponent <HealthScript>(); pwrMngr.PowerSetup(systemType, powerReq); originMedBayScr = GetOriginMedBay(); if (this == originMedBayScr) { isOrigin = true; } //originEngScr.fullPwrReq += powerReq; if (isOrigin) { pwrMngr.AddToSysScrList(systemType, sysScr); StartCoroutine(HealRoutine()); } }
void BeingAttackedAction(ref AbstractPlanet planet) { if (planet.isContested) { if (ValidPlanetForTraining(ref planet)) { planet.TrainSoldiers(true); } planet.isRequestingSoldiers = true; //Unload my ship if I have one ship = planet.ships [Indices.SHIP_ENEMY]; if (ship) { ship.StopLoadingSoldiersToShip(); //Send units to nearest neighbor if (ship.soldiersOnBoard > 0) { AbstractPlanet target = NearestNeighbor(planet); LaunchShip(planet, target, planet.adjacentPaths, ship); } } action++; actionHappened = true; } else { planet.isRequestingSoldiers = false; } }
void NeighborAttackedAction(ref AbstractPlanet planet) { foreach (AbstractPlanet neigh in planet.adjacentPlanet) { if (actionHappened) { continue; } if (neigh.isContested && planet.planetOwnership == AbstractPlanet.Ownership.Enemy) //Is my neighbor planet being attacked { if (ValidPlanetForTraining(ref planet)) { planet.TrainSoldiers(true); } planet.isFeeding = true; float totalUnits = neigh.enemySoldiers + neigh.playerSoldiers; if (neigh.playerSoldiers / totalUnits > 0.50f) { ship = planet.CreateShip(AbstractPlanet.Ownership.Enemy); if (ship.soldiersOnBoard == ship.soldierCapacity || (!CanNewUnitsBeCreated() && ship.soldiersOnBoard > 0)) { LaunchShip(planet, neigh, planet.adjacentPaths, ship); } else if (!ship.GetIsLoading()) { ship.StartLoadingSoldiersToShip(planet); } } action++; actionHappened = true; } } }
public Vector3 applyForces(ref Vector3 shipPos, float shipMass, float timestep) { Vector3 r = shipPos - transform.position; Vector3 pushVelocity = new Vector3(0.0f, 0.0f, 0.0f); Vector3 pushForce = new Vector3(0.0f, 0.0f, 0.0f); if (r.magnitude < innerRadius) { //destroy ship via explosion ObjectGeneratorScript obs = GameObject.Find("ObjectGenerator").GetComponent <ObjectGeneratorScript>(); GamePlayManagerScript gms = GameObject.Find("GamePlayManager").GetComponent <GamePlayManagerScript>(); ShipScript shipscript = obs.playerShip.GetComponent <ShipScript>(); shipscript.DieWithExplosion(); gms.StartCoroutine("GameOverandReset"); } else { pushVelocity.x = (outerRadius / r.x) * strength; pushVelocity.y = (outerRadius / r.y) * strength; pushVelocity.z = (outerRadius / r.z) * strength; pushForce = pushVelocity * (shipMass / timestep); } return(pushForce); }
/* * private IEnumerator Test () { * while (true) { * Vector3 _vect = Vector3.left; * rb.MovePosition (transform.position + _vect * speed / 0.05f); * * yield return new WaitForSeconds (0.05f); * } * } */ public void SetCrewCamValues(ShipScript _ship, bool _usingTerminal, int _shipID) { if (_usingTerminal) { targetedShip = _ship; crewShipCam.transform.SetParent(targetedShip.transform); //Debug.LogError ("cam size: " + crewShipCam.orthographicSize); crewShipCam.orthographicSize = targetedShip.ShipCam.orthographicSize; //Debug.LogError ("cam size: " + crewShipCam.orthographicSize); cam.gameObject.SetActive(false); crewShipCam.gameObject.SetActive(true); //crewShipCam.transform.position = new Vector3 (0, 0, -20); crewShipCam.transform.position = _ship.ShipCam.transform.position; targetingCursor.transform.position = _ship.transform.position; /* * Matrix4x4 _mat = crewShipCam.projectionMatrix; * if (NetManager.Instance.localPlayerID == _shipID) { * _mat *= Matrix4x4.Scale (new Vector3 (1, 1, 1)); * } else { * _mat *= Matrix4x4.Scale (new Vector3 (-1, 1, 1)); * } * crewShipCam.projectionMatrix = _mat; */ } cam.gameObject.SetActive(!_usingTerminal); crewShipCam.gameObject.SetActive(_usingTerminal); }
/* * public int [,] LoadShip (string _shipName) * { * int[,] loadedStats = SaveLoadManager.LoadShip (_shipName); * * return loadedStats; * } */ //actually places the ship //public void PlacementLoop (int[,] loadedStats, int playerID) public void PlaceShip(string _shipStr, int _z, int _ownerID) { ShipScript _ship = LevelManager.Instance.Ships[_z].GetComponent <ShipScript>(); _ship.OwnerID = _ownerID; string[] _strArr = _shipStr.Split('-'); for (int i = 0; i < _strArr.Length; i++) { string [] _strArrTwo = _strArr [i].Split(','); string _name = _strArrTwo [0]; int _type = int.Parse(_strArrTwo [1]); int _x = int.Parse(_strArrTwo [2]); int _y = int.Parse(_strArrTwo [3]); Point _point = new Point(_x, _y, _z); PlaceObject(_name, _type, _point); } //Debug.Log ("playerID: " + _playerID); //the placement loop should be seperated //for (int i = 0; i < loadedStats.GetLength(0); i++) { // PlaceObjOnLocation (loadedStats [i, 0], loadedStats [i, 1], playerID, loadedStats [i, 2], loadedStats [i, 3], loadedStats [i, 4]); //} }
private void HandleAsteroidSplitExplosion() { float blastRadius = mass * 2f; float blastForce = 40f * mass; Collider2D[] hitColliders = Physics2D.OverlapCircleAll(transform.position, blastRadius); foreach (Collider2D col in hitColliders) { Vector3 pos = col.transform.position; Vector2 impulse = pos - transform.position; impulse /= impulse.magnitude; impulse *= blastForce; float percent = (blastRadius - Vector3.Distance(pos, transform.position)) / blastRadius; if (col.tag == "Ship") { ShipScript ship = col.GetComponent <ShipScript>(); ship.TakeHit(impulse / 2 * percent, pos); ship.ApplyDamage(1.0f * mass * percent, 0.0f); } else if (col.tag == "Satellite" || col.tag == "sAsteroid" && col.gameObject != gameObject) { //Rigidbody2D roidRb = col.GetComponent<Rigidbody2D>(); //roidRb.AddForce( impulse * percent, ForceMode2D.Impulse ); Satellite sat = col.GetComponent <Satellite>(); sat.ApplyDamage(0, impulse * 2 * percent, pos, false); } } }
public ShipComponents(GameObject go) { ship = go; rb = ship.GetComponent <Rigidbody> (); scrp = ship.GetComponent <ShipScript> (); turr = ship.GetComponentsInChildren <Transform>().ToList <Transform>(); turr.RemoveAll(x => x.gameObject.tag != "Turret"); }
void Start() { shipScript = ships[shipIndex].GetComponent <ShipScript>(); nextBtn.onClick.AddListener(() => NextShipClicked()); rotateBtn.onClick.AddListener(() => RotateShipClicked()); replayBtn.onClick.AddListener(() => ReplayClicked()); enemyShips = enemyScript.PlaceEnemyShips(); }
public ShipScript CreateShip(Ownership ownership) { ShipScript ship = null; switch (ownership) { case Ownership.Player: if (ships[Indices.SHIP_PLAYER] == null) { switch (planetOwnership) { case Ownership.Player: ship = ShipInstantiation(Indices.SHIP_PLAYER); break; default: if (playerSoldiers > 0) { ship = ShipInstantiation(Indices.SHIP_PLAYER); } break; } } else { return(ships[Indices.SHIP_PLAYER]); } break; case Ownership.Enemy: if (ships[Indices.SHIP_ENEMY] == null) { switch (planetOwnership) { case Ownership.Enemy: ship = ShipInstantiation(Indices.SHIP_ENEMY); break; default: if (enemySoldiers > 0) { ship = ShipInstantiation(Indices.SHIP_ENEMY); } break; } } else { return(ships[Indices.SHIP_ENEMY]); } break; case Ownership.Neutral: //This shouldn't happen break; } return(ship); }
private ShipScript CreateShip(ShipScript prefab) { ShipScript ship = Instantiate(prefab) as ShipScript; ship.gameObject.SetActive(true); ship.transform.SetParent(ManagerScript.Instance.shipContainer.transform); ship.GetShipRenderer().enabled = false; return(ship); }
private void PlaceShip(GameObject tile) { shipScript = ships[shipIndex].GetComponent <ShipScript>(); shipScript.ClearTileList(); Vector3 newVec = shipScript.GetOffsetVec(tile.transform.position); ships[shipIndex].transform.localPosition = newVec; }
public static void UnregisterConnection(GameObject obj, GameObject obj2) { ShipScript script = GetShipScript(); if (script != null) { script.RemoveConnection(obj, obj2); } }
// Use this for initialization void Start() { mouse_look = transform.FindChild("direction").GetComponent <MouseLook2>(); mouse_look_camera = transform.FindChild("CameraFP").GetComponent <MouseLook>(); ShipScr = transform.FindChild("Ship").GetComponent <ShipScript>(); old_camera_rot = transform.rotation; }
// Use this for initialization void Start() { _instance = this; fadingOff = true; Target.gameObject.SetActive(false); Color c = Ship.GetComponent <Image>().color; c.a = 1f; Ship.GetComponent <Image>().color = c; }
public static void InitializeShipGraph() { ShipScript script = GetShipScript(); if (script != null) { List <GameObject> gameObjects = GetGameObjects(); script.SetConnectableObjects(gameObjects); } }
//helper function public void PlayerCreateShip() { Debug.Log("create ship for player"); ShipScript ship = planetScript.CreateShip(AbstractPlanet.Ownership.Player); if (ship != null) { ManagerScript.Instance.audioManager.PlaySound("ButtonClick"); planetScript.LoadSoldiersToShip(ship); } }
public static bool ShipIsValid() { ShipScript script = GetShipScript(); if (script != null) { return(script.IsValidShip()); } return(false); }
private void Start() { CouchMode = CasheScript.Instance.CouchMode; //DepartTile = transform.parent.parent.GetComponent <TileScript> (); //crewPos = DepartTile.GridPosition; //sets crew alignment //whose crew 's dat? CrewOrigin = CrewPos.Z; //mayhap unnessesary //if obj in hangar and void differ. if (NetManager.Instance != null) { //if (NetManager.Instance.localPlayerID == CrewPos.Z) { ShipScript _ship = LevelManager.Instance.Ships[crewPos.Z].GetComponent <ShipScript>(); if (NetManager.Instance.localPlayerID == _ship.OwnerID) { IsLocalCrew = true; } else { IsLocalCrew = false; } player = NetManager.Instance.playerList [CrewPos.Z]; player.crewList.Add(this); player.SetCrewIndex(); if (!CouchMode) { transform.GetChild(0).GetComponent <CrewSelect>().AddToHash(IsLocalCrew); /* * TileScript _tile = LevelManager.Instance.Tiles[CrewPos]; * RoomScript _room = _tile.transform.GetChild(0).GetChild(0).GetComponent<RoomScript>(); * if (hScr == null) { * Debug.LogError("hScr == null!"); * } else { * _room.EnterRoom(hScr); * } */ } /* * if (CouchMode) { * rb = gameObject.GetComponent <Rigidbody2D> (); * } */ } //to avoid null dmgLoop = DmgLoop(0); }
public void ApplyFireDamage(ShipScript otherShip) { LP -= otherShip.firePower; if (lifePointsDisplay != null) { lifePointsDisplay.text = lifePointsLabel + LP; } if (LP <= 0) { explode(); } }
void OnCollisionEnter(Collision collision) { if (isServer) { ShipScript sc = collision.gameObject.GetComponent <ShipScript>(); if (sc) { sc.setDamage(10); sc.setSpeed(0); } } }
void Launch(PathScript path) { ShipScript ship = planetScript.ships [Indices.SHIP_PLAYER]; ship.gameObject.SetActive(true); AbstractPlanet targetPlanet = path.GetDirectionStartingFrom(transform).end.gameObject.GetComponent <AbstractPlanet>(); if (targetPlanet != null) { ship.LaunchShipOnPath(path, transform, targetPlanet); } }
void Start() { //setup Singleton if (instance == null) { instance = this; DontDestroyOnLoad(gameObject); } else { Destroy(gameObject); } }
void Update() { if (Ship != null) { if (Vector3.Distance(transform.position, Player.position) <= Vector3.Distance(transform.position, Ship.position)) { transform.LookAt(Player); if (Vector3.Distance(transform.position, Player.position) <= AttackDistance / 2) { //Debug.Log("Damaging Player"); //GetComponent<Rigidbody>().velocity = Vector3.zero; //GetComponent<Rigidbody>().angularVelocity = Vector3.zero; } else { //Debug.Log("No Damage"); transform.position += transform.forward * MoveSpeed * Time.deltaTime; } } else { transform.LookAt(Ship); if (Vector3.Distance(transform.position, Ship.position) <= AttackDistance) { //Debug.Log("Damaging Ship"); if (Ship.gameObject != null) { ShipScript ShipData = Ship.GetComponent <ShipScript>(); if (ShipData.isAlive() && !CoolingDown) { ShipData.damageShip(CurrentDamage); //Debug.Log("Damaged Ship for "+CurrentDamage+" Damage!"); StartCoroutine(JustAttacked()); } } //GetComponent<Rigidbody>().velocity = Vector3.zero; //GetComponent<Rigidbody>().angularVelocity = Vector3.zero; } else { //Debug.Log("No Damage"); transform.position += transform.forward * MoveSpeed * Time.deltaTime; } } } }
void Start() { parent = transform.parent.gameObject.GetComponent<ShipScript>(); system = GameObject.FindGameObjectWithTag("System"); rpcScript = system.GetComponent<RPCScript>(); if (this.name == "Bow") gameObject.renderer.material.color = Color.black; if (this.name == "Stern") gameObject.renderer.material.color = Color.white; if (parent.player != parent.gameScript.myname) { Debug.Log ("parent name " + parent.player + " gamescript name " + parent.gameScript.myname); Debug.Log ("not my ship so disable renderer"); gameObject.renderer.enabled = false; Debug.Log ("Disabling visibility on cell"); parent.GetCellForSection(this.gameObject).SetVisible(false); } }
// Use this for initialization void Start() { Debug.Log("Game start!"); shipScript = GameObject.Find ("Ship").GetComponent<ShipScript>(); ship = GameObject.FindGameObjectWithTag ("ship"); ship = GameObject.FindGameObjectWithTag ("lighthouse"); questList = new List<Quests>(); generateQuests(); generateLevel(level); }
// Use this for initialization void Start() { shipScript = GetComponent<ShipScript>(); rb = GetComponent<Rigidbody>(); pfx = GetComponent<PlayerFX>(); playerRespawn = GetComponent<PlayerRespawn>(); hullOnline = GetComponent<HullOnline>(); hullOnline.RB = rb; hullOnline.SetBuoyancy = GetComponent<BuoyancyScript>(); Reset(); }
// Use this for initialization void Start() { shipAttributes = transform.parent.GetComponent<ShipAttributesOnline>(); ship = transform.parent; shipScript = ship.GetComponent<ShipScript>(); lineRenderer = GetComponent<LineRenderer>(); currentCharge = transform.childCount; cannonsCount = transform.childCount; }