public void Spawn(Vector2 speedVector, Vector2 initSpeed, int attackerIndex = -1) { this.attackerIndex = attackerIndex; if (speedVector == Vector2.zero && initSpeed == Vector2.zero) { ChangeLayerToRestState(); } else { ChangeLayerToMotionState(); } _rb = gameObject.GetComponent <Rigidbody2D>(); _rb.velocity = initSpeed + speedVector * LAUNCH_FORCE; _rb.AddForce(speedVector * LAUNCH_FORCE, ForceMode2D.Impulse); _col = GetComponent <Collider2D>(); _col.enabled = false; Invoke("EnableCollision", 0.05f); _forceFlag = true; _lastSpeedVector = speedVector * 0.5f; Invoke("DisableForce", 0.15f); ColorSetter.UpdateModelColor(gameObject, mineTypeColor); }
public void Init(int index, InputManager controls, Color color) { _rb = GetComponent <Rigidbody2D>(); _initMass = _rb.mass; _initDrag = _rb.drag; _input = controls; _playerIndex = index; _shipColor = color; ColorSetter.UpdateModelColor(BodyModel, _shipColor); SpeedIndicator = Instantiate(SpeedIndicator, new Vector3(0, 0, 0), Quaternion.identity, null); SpeedIndicator.transform.parent = gameObject.transform; SpeedIndicator.transform.localPosition = new Vector3(0, -0.3f, 0); EventManager.Subscribe <Event_PlayerMineCollect>(this, OnMineCollect); EventManager.Subscribe <Event_MaximumMinesCount_Change>(this, OnMineMaxCountChange); EventManager.Subscribe <Event_ControlsLockState_Change>(this, OnControlsLockStateChange); }
void UpdateInternals() { //_collectedMines int maxMines = GameState.Instance.MaxMinesBeforeExplosion; //float scale = 0.1f + 0.9f *( (float)_collectedMines.Count() / (float) maxMines ); //InternalsModel.transform.localScale = new Vector3(scale, scale, scale); foreach (var slot in MineSlots) { slot.SetActive(false); } int slotIndex = 0; foreach (var mine in _collectedMines.Mines) { MineSlots[slotIndex].SetActive(true); Color mineColor = Mine.MineTypeToColor(mine); if (_lashDashIncreasmentStartingTime > 0f) { // It is indicator of full-dash collected mineColor = Color.magenta; } ColorSetter.UpdateModelColor(MineSlots[slotIndex], mineColor); slotIndex++; slotIndex = Mathf.Clamp(slotIndex, 0, MineSlots.Count - 1); } CalcShipMass(); if (_collectedMines.Count() > maxMines) { Kill(); } ActualizeLayer(); }
void Update() { if (_lockFlag) { return; } if (Input.GetKeyDown(KeyCode.Return) && JoinObjects.Count > 0) { GoToGame(); } int i = 0; while (i < playersConnected) { TeamUtility.IO.PlayerID playerId = (TeamUtility.IO.PlayerID)System.Enum.GetValues(typeof(TeamUtility.IO.PlayerID)).GetValue(i); if (InputMng.GetButtonDown("Button A", playerId)) { PlayerInfo info = _holder.playersInfos.Find(infs => infs.playerNumber == i); if (info != null) { _holder.RemovePlayerInfo(info); GameObject hideGO = JoinObjects.Find(objs => objs.name == joinKeysPrefixes[i]); if (hideGO) { hideGO.SetActive(false); } } else { //Color col = UnityEngine.Random.ColorHSV(0, 1, 1, 1, 1, 1); Color col = PlayerColors[i]; _holder.AddPlayerInfo(new PlayerInfo(col, i)); GameObject showGO = JoinObjects.Find(objs => objs.activeSelf == false); if (showGO) { showGO.SetActive(true); showGO.name = joinKeysPrefixes[i]; ColorSetter.UpdateModelColor(showGO, col); } } PlayMenuClick(); } i++; } foreach (var player in _holder.playersInfos) { TeamUtility.IO.PlayerID playerId = (TeamUtility.IO.PlayerID)System.Enum.GetValues(typeof(TeamUtility.IO.PlayerID)) .GetValue(player.playerNumber); if (InputMng.GetButtonDown("Start", playerId)) { player.ready = !player.ready; GameObject readyGOParent = JoinObjects.Find(objs => objs.name == joinKeysPrefixes[player.playerNumber]); readyGOParent.transform.Find("ReadyFlag").gameObject.SetActive(player.ready); PlayMenuClick(); } } bool _allReady = true; if (_holder.playersInfos.Count > 1) { foreach (var player in _holder.playersInfos) { if (!player.ready) { _allReady = false; } } } else { _allReady = false; } if (_allReady) { _lockFlag = true; Invoke("GoToGame", 0.5f); } }