private void Construct(ShipBehaviour shipBehaviour, InteractionData interactionData) { _shipBehaviour = shipBehaviour; _interactionData = interactionData; _camera = Camera.main; _hits = new RaycastHit[10]; }
public void ManuallyEndLevel() { ShipBehaviour ship = FindObjectOfType <ShipBehaviour>(); ship.Die(); ShowEndWnidow(); }
public void ReceiveDamage(int damage, ShipBehaviour origin) { if (health <= 0) { return; } health = Mathf.Max(0, health - damage); if (health > 0) { float percentHp = (float)health / maxHealth; healthBarInstance.hpSlider.value = percentHp; float red, green; if (percentHp < 0.5f) { red = 255f; green = 255f - ((0.5f - percentHp) * 510f); } else { red = 255f - ((percentHp - 0.5f) * 510f); green = 255f; } healthBarInstance.sliderImage.color = new Color(red / 255f, green / 255f, 0, 255f); } GetComponent <Animator>().SetInteger("hp", health); if (health <= 0) { healthBarInstance.sliderImage.color = new Color(0, 0, 0, 0); Destroy(healthBarInstance.gameObject); GameManager.instance.ShipDestroyed(this, origin); StartCoroutine(Explode()); } }
protected virtual void OnEnable() { movement = GetComponent <ShipMovement>(); behaviour = GetComponent <ShipBehaviour>(); StartEffect(); }
// Initialize Ship private ShipBehaviour createShip() { GameObject ship_obj = new GameObject("Ship"); ShipBehaviour new_ship = ship_obj.AddComponent <ShipBehaviour>(); return(new_ship); }
public virtual void Inicialice() { direction.x = Random.Range(-direction.x, direction.x); enemy = GetComponent <ShipBehaviour>(); enemy.SetAxis(direction); enemy.SetFly(true); }
// Use this for initialization /// <summary> /// Loads system components and finds the droid ship + its mouse components. /// </summary> void Start() { /*var rectTransform = healthBar.GetComponent<RectTransform> (); * // Set initial positions so we know what the maximum value is. * healthInitialXPos = rectTransform.position.x; * energyInitialXPos = rectTransform.position.x; * * healthPos = rectTransform.position; * // Get the width of the bars - should be the same for both. * barWidth = rectTransform.rect.size.x; * //barWidth *= 10; // Scaling. I'm not sure how to do this better at this time. */ //find or create these system components level = ObjectFinder.FindOrCreateComponent <LevelManager> (); loader = ObjectFinder.FindOrCreateLevelLoader(); eventPublisher = ObjectFinder.FindOrCreateComponent <EventPublisher> (); //find the player to get the the mouse components and ship behaviour var ship = GameObject.Find("Player"); xaxis = ship.GetComponent <MouseLook> (); yaxis = GameObject.Find("Attachments").GetComponent <MouseLook> (); shipBehaviour = ship.GetComponent <ShipBehaviour> (); //initialize the sensitivity to whatever is currently set in the editor sens = xaxis.sensitivityX; //initialize our molecule_tag -> texture mapping moleculeForTexture = new Dictionary <string, Texture>() { { "Water", waterTexture }, { "Methane", methaneTexture } }; }
// Once the projectile collides with any object, only collides with ships void OnCollisionEnter2D(Collision2D collision) { GameObject collidedObject = collision.gameObject; //Debug.Log("Collided with " + collidedObject.name); //ignore any collisions with the owner ship just in case if (collidedObject.gameObject.Equals(ownerShip)) { return; } if (collidedObject.gameObject.tag == "ship") //check if the collided object is a ship { try { //Try getting the Player Ships' Script PlayerShipBehaviour collidedScript = collidedObject.GetComponent <PlayerShipBehaviour>(); collidedScript.health -= damage; //decrease player's health Destroy(gameObject); } catch (NullReferenceException) { //Get Ship's Script if player ship script doesn't exist ShipBehaviour collidedScript = collidedObject.GetComponent <ShipBehaviour>(); collidedScript.health -= damage; //decrease ships' health Destroy(gameObject); } } //Maybe useful in the future - different kind of weapon? - ignores further collisions with the collidedObject Physics2D.IgnoreCollision(GetComponent <Collider2D>(), collidedObject.GetComponent <Collider2D>(), true); }
public void Flee(Vector2 location, float distance) { _fleeDistance = distance; Speed = 3.5f; _shipBehaviour = ShipBehaviour.Flee; _destination = location; }
void Start() { ship = GetComponent <ShipMovement>(); player = GetComponent <ShipBehaviour>(); _camera = Camera.main; }
public void Initialize( SolarSystemBehaviour solarSystemBehaviour, SolarSystem solarSystem, ShipBehaviour shipBehaviour, GameData gameData) { _solarSystemBehaviour = solarSystemBehaviour; _solarSystem = solarSystem; _shipBehaviour = shipBehaviour; _gameData = gameData; _shipBehaviour.RunOutOfFuelEvent += () => { _gameData.Score += _shipBehaviour.Ship.LifeSupport.Value; _gameData.GameState = GameState.Failed; }; _shipBehaviour.TargetReachedEvent += () => { if (_shipBehaviour.Ship.LifeSupport.Value >= _gameData.RequiredLifeSupport) { var newScore = _shipBehaviour.Ship.Fuel.Value + _shipBehaviour.Ship.LifeSupport.Value; _gameData.RemainingUpgrades.Value += Mathf.FloorToInt(newScore / UpgradeCost); _gameData.Score += newScore; _gameData.GameState = GameState.Successful; } }; _gameData.GameState = GameState.Running; }
void Initialize() { ship = GetComponent <ShipBehaviour>(); direction.y = Random.Range(-direction.y, direction.y); ship.setAxis(direction); ship.SetFly(true); }
private void OnCollisionEnter2D(Collision2D collision) { ShipBehaviour sb = collision.gameObject.GetComponent <ShipBehaviour>(); if (sb != null && health > 0) { sb.ReceiveDamage(crashDamage, this); } this.ReceiveDamage(this.maxHealth, this); }
void Awake() { controller = GetComponent <CharacterController>(); VikingControlsScript = GetComponent <VikingControls>(); vikingShipObject = GameObject.FindWithTag("Viking_Ship"); ShipBehaviourScript = vikingShipObject.GetComponentInChildren <ShipBehaviour>(); ShipInsideColliderScript = vikingShipObject.GetComponentInChildren <ShipInsideCollider>(); ShipLandingColliderScript = vikingShipObject.GetComponentInChildren <ShipLandingCollider>(); }
protected void CheckBehaviour() { if (Mathf.Abs ((transform.position - player.transform.position).magnitude) <= chaseDistance) { if (!(behaviour is ChaseBehaviour)) { behaviour = new ChaseBehaviour (this, player); } } else if (!(behaviour is PatrolBehaviour)) { behaviour = new PatrolBehaviour (this, bounds); } }
public void Initialize(ShipBehaviour ship, PlaneConfig configs) { Ship = ship; _move.Initialize(configs.GetMaxMoveSpeed, configs.GetMinMoveSpeed, configs.GetAngularSpeed); if (_planeFly == null) { _planeFly = new PlaneFly(this); } MaxDistancePos = Ship.GetMaxPlaneDistance; RestartPlane(); }
void Awake() { if (S == null) { S = this; } else { Debug.LogError("Cant do two ships man"); } }
public void battleStart(GameObject oldCam, ShipBehaviour ally, EnShip enemy) { cam = oldCam; dead = enemy; alive = ally; cam.transform.position = on; a1.changeText(ally.title); a2.changeText(ally.desc); e1.changeText(enemy.title); e2.changeText(enemy.desc); }
public void ShipDestroyed(ShipBehaviour ship, ShipBehaviour killer) { if (ship.GetComponent <PlayerManager>()) { EndSession(); } else if (killer.GetComponent <PlayerManager>()) { GetPoint(); } }
private Vector2 FleeBehaviour() { var directionVector = -(_destination - Center); float vectorLength = directionVector.Length(); if (vectorLength > _fleeDistance) { _shipBehaviour = ShipBehaviour.Wander; } directionVector.Normalize(); return(directionVector); }
private void OnTriggerEnter2D(Collider2D col) { ShipBehaviour ship = col.gameObject.GetComponent <ShipBehaviour>(); if (ship != null && ship != owner) { registeredHit = true; ship.ReceiveDamage(damage, owner); GetComponent <Animator>().SetTrigger("Explode"); GetComponent <Collider2D>().enabled = false; } }
void Start() { once = true; outB.x = -26; outB.y = 12; outB.z = 0; turn = 1; selected_ship = null; selected_planet = null; spaces = new Space[61]; ships = new ShipBehaviour[5]; texts = new TextBehaviour[5]; planets = new Planet[3]; fleet = new EnShip[2]; productions = new GameObject[3]; prod_choices = new Dropdown[3]; ddvalues = new int[3]; getShips(); grid = transform.GetChild(1).gameObject.GetComponent <GridBehaviour>(); et1 = transform.GetChild(2).gameObject.GetComponent <EndTurn>(); getTexts(); getPlanets(); getDDMenus(); getSpaces(); highlight = transform.GetChild(6).gameObject; enSpawner = transform.GetChild(7).gameObject.GetComponent <Hostile>(); arena = transform.GetChild(8).gameObject.GetComponent <BattleEnviro>(); bank = transform.GetChild(9).gameObject.GetComponent <Resources>(); cam = transform.GetChild(10).gameObject; ships[0].setPrev(spaces[1]); ships[1].setPrev(spaces[40]); planets[0].movement(spaces[11]); planets[1].movement(spaces[23]); planets[2].movement(spaces[58]); Select(); }
private Vector2 SeekBehaviour() { var directionVector = _destination - Center; float vectorLength = directionVector.Length(); if (vectorLength < SeekDistance) { _shipBehaviour = ShipBehaviour.Wander; return(Vector2.Zero); } directionVector.Normalize(); return(directionVector); }
// Use this for initialization void Start() { if (GameObject.Find("Level") != null) { eventPublisher = GameObject.Find("Level").GetComponent <EventPublisher> (); } else { Debug.Log("No level game object in scene: " + Application.loadedLevelName); } m_shipBhv = gameObject.GetComponent <ShipBehaviour>(); setupMouse(); lockMouse(); }
void UpdateBuffs() { ShipBehaviour ship1 = AllShips.Ships[player1ship]; ShipBehaviour ship2 = AllShips.Ships[player2ship]; player1buffs[2].gameObject.active = true; player1buffs[1].gameObject.active = true; player2buffs[2].gameObject.active = true; player2buffs[1].gameObject.active = true; player1buffs[0].sprite = ship1.buff1[player1buffsindex[0]].sprite; player2buffs[0].sprite = ship2.buff1[player2buffsindex[0]].sprite; if (ship1.buff3.Length == 0) { player1buffs[2].gameObject.active = false; } else { player1buffs[2].sprite = ship1.buff3[player1buffsindex[2]].sprite; } if (ship1.buff2.Length == 0) { player1buffs[1].gameObject.active = false; } else { player1buffs[1].sprite = ship1.buff2[player1buffsindex[1]].sprite; } if (ship2.buff3.Length == 0) { player2buffs[2].gameObject.active = false; } else { player2buffs[2].sprite = ship2.buff3[player2buffsindex[2]].sprite; } if (ship2.buff2.Length == 0) { player2buffs[1].gameObject.active = false; } else { player2buffs[1].sprite = ship2.buff2[player2buffsindex[1]].sprite; } }
private void Create(ShipBehaviour ship) { if (ship.OverFlowCheck()) { ship.StartFreePlane(ship); return; } var plane = Instantiate(prefabPlane, transform.position + new Vector3(.5f, .5f, 0), Quaternion.identity); var planeBehaviour = plane.GetComponent <PlaneBehaviour>(); planeBehaviour.Initialize(ship, configs); ship.AddPlane(planeBehaviour); OnNewPlane?.Invoke(planeBehaviour); _input.OnHuntBegin += planeBehaviour.StartHunt; }
// Use this for initialization void Start() { var util = GameObject.Find("Utilities"); if (util == null) { util = GameObject.CreatePrimitive(PrimitiveType.Cube); util.AddComponent <LevelLoader>(); util.name = "Utilities"; } loader = util.GetComponent <LevelLoader> (); GUIMan.UpdateCollectedMolecules(Flatten(collected)); ship = GameObject.Find("Player").GetComponent <ShipBehaviour>(); SetCheckpoint(ship.transform.position); setupHierarchy(); }
public override void OnTriggerEnter2D(Collider2D collision) { if (collision.tag == "UFO") { if (transform.position.y < 4.5f && transform.position.y > -4.5f) { ShipBehaviour E = collision.gameObject.GetComponent <ShipBehaviour>(); E.SetLife(damage); weapon = GameObject.FindGameObjectWithTag("weapons").GetComponent <Weapon>(); ammoTransform = GameObject.Find("Ammo").GetComponent <Transform>(); cartridge = weapon.GetCartridge(); cannon.ShotBullet(cartridge[0]); transform.rotation = initRot; transform.position = iniPos; } } }
// Initialization Event void Start() { // Components prim = new DrawPrim(screen_width, screen_height); util = new DrawUtil(prim); util.drawFill(Color.clear); screen_tex = prim.texture; GameObject img_obj = createImage(screen_tex); img_obj.name = "Screen"; img = img_obj.GetComponent <RawImage>(); img.GetComponent <RectTransform>().localScale = new Vector3(screen_scale, screen_scale, 1f); // Variables camera_position = Vector2.zero; player_ship = gameObject.AddComponent <ShipBehaviour>(); }
void Start() { Main.mode = Mode.Casual; Screen.orientation = ScreenOrientation.PortraitUpsideDown; start = false; boss = false; spawn = true; autoShoot = true; // init ship ShipBehaviour ship = AllShips.Ships[Game.ship1]; player.GetComponent <SpriteRenderer>().sprite = ship.sprites[2]; player.sprites = ship.sprites; player.health = ship.health; player.maxHealth = ship.health; player.shield = ship.shield; player.maxShield = ship.shield; player.shieldReloadDelay = ship.shieldReloadDelay; player.shieldReloadSpeed = ship.shieldReloadSpeed; player.shootDelay = new int[] { 30, 30, 30 }; player.Init(); ItemEvents.player = player; ItemEvents.i = 0; if (ship.buff1 != null && ship.buff1.Length != 0 && Game.buffs1 != null) { ship.buff1[Game.buffs1[0]].trigger.Invoke(); } if (ship.buff2 != null && ship.buff2.Length != 0 && Game.buffs1 != null) { ship.buff2[Game.buffs1[1]].trigger.Invoke(); } if (ship.buff3 != null && ship.buff3.Length != 0 && Game.buffs1 != null) { ship.buff3[Game.buffs1[2]].trigger.Invoke(); } }
public virtual void OnTriggerEnter2D(Collider2D collision) { if (collision.tag == "UFO") { if (transform.position.y < 4.5f && transform.position.y > -4.5f) { transform.rotation = initRot; transform.position = iniPos; ShipBehaviour E = collision.gameObject.GetComponent <ShipBehaviour>(); E.SetLife(damage); if (SoundFX != null) { SoundFX2.pitch = Random.Range(0.97f, 1.23f); SoundFX2.volume = Random.Range(0.97f, 1.23f); SoundFX2.Play(); } } } }
// Use this for initialization void Start() { if (GameObject.Find ("Level") != null) { eventPublisher = GameObject.Find ("Level").GetComponent<EventPublisher> (); } else { Debug.Log ("No level game object in scene: " + Application.loadedLevelName); } m_shipBhv = gameObject.GetComponent<ShipBehaviour>(); setupMouse(); lockMouse(); }
// Use this for initialization /// <summary> /// Loads system components and finds the droid ship + its mouse components. /// </summary> void Start() { /*var rectTransform = healthBar.GetComponent<RectTransform> (); // Set initial positions so we know what the maximum value is. healthInitialXPos = rectTransform.position.x; energyInitialXPos = rectTransform.position.x; healthPos = rectTransform.position; // Get the width of the bars - should be the same for both. barWidth = rectTransform.rect.size.x; //barWidth *= 10; // Scaling. I'm not sure how to do this better at this time. */ //find or create these system components level = ObjectFinder.FindOrCreateComponent<LevelManager> (); loader = ObjectFinder.FindOrCreateLevelLoader (); eventPublisher = ObjectFinder.FindOrCreateComponent<EventPublisher> (); //find the player to get the the mouse components and ship behaviour var ship = GameObject.Find ("Player"); xaxis = ship.GetComponent<MouseLook> (); yaxis = GameObject.Find ("Attachments").GetComponent<MouseLook> (); shipBehaviour = ship.GetComponent<ShipBehaviour> (); //initialize the sensitivity to whatever is currently set in the editor sens = xaxis.sensitivityX; //initialize our molecule_tag -> texture mapping moleculeForTexture = new Dictionary<string, Texture>(){ {"Water", waterTexture}, {"Methane", methaneTexture} }; }
protected override void RespawnBehaviour() { behaviour = null; transform.position = spawnPosition; base.RespawnBehaviour (); }
// Use this for initialization void Start() { ship = GetComponent<ShipBehaviour>(); tanks = new Dictionary<GameColor, float>(); Screen.showCursor = false; if (giveAll) { currentColor = GameColor.Green; tanks[GameColor.Red] = tankSize; tanks[GameColor.Green] = tankSize; tanks[GameColor.Blue] = tankSize; tanks[GameColor.Yellow] = tankSize; tanks[GameColor.Purple] = tankSize; tanks[GameColor.Cyan] = tankSize; } }