public void InitUnit(UnitOwner owner) { this.owner = owner; CreateAimComponent(); aimComponent.Init(this); moralComponent = gameObject.AddComponent <UnitMoralComponent>(); if (owner == UnitOwner.PLAYER) { transform.Find("SpriteEnemy").gameObject.SetActive(false); transform.Find("SpritePlayer").gameObject.SetActive(true); transform.Find("SpritePlayer/shotFire").gameObject.SetActive(false); if (transform.Find("SpritePlayer/flag") != null) { transform.Find("SpritePlayer/flag").gameObject.SetActive(false); } } else { transform.Find("SpriteEnemy").gameObject.SetActive(true); transform.Find("SpriteEnemy/shotFire").gameObject.SetActive(false); if (transform.Find("SpriteEnemy/flag") != null) { transform.Find("SpriteEnemy/flag").gameObject.SetActive(false); } transform.Find("SpritePlayer").gameObject.SetActive(false); } soldierSprite = transform.GetComponentInChildren <SoldierSprite>(); hitpoint = GetParams().hitpoints; SetState(new RunUnitState(this), unitState); }
//public void Deinit() //{ //} // Update is called once per frame void Update() { if (Time.timeSinceLevelLoad - levelStartTime < InitMoraleImmuneDuration) { return; } if (Time.timeSinceLevelLoad - lastMoraleCheckTime < MoraleCheckInterval) { return; } if (!BolkonskyModeOn) { collectiveMorale = 0; RaycastHit2D[] raycastHits = Physics2D.CircleCastAll(transform.position, unit.GetParams().moralCheckRadius, Vector2.zero, 0); foreach (RaycastHit2D hit in raycastHits) { if (hit.collider == null) { continue; } UnitMoralComponent otherUnit = hit.collider.GetComponent <UnitMoralComponent>(); if (otherUnit == null || otherUnit == this || hit.collider != otherUnit.unit.unitCollider) { continue; } if (otherUnit.unit.GetOwner() == unit.GetOwner()) { collectiveMorale += otherUnit.CurrentMorale; } else { collectiveMorale -= otherUnit.CurrentMorale; } } SwitchMoralBreak(collectiveMorale); lastMoraleCheckTime = Time.timeSinceLevelLoad; } else { if (Time.timeSinceLevelLoad - BolkonskyModeStartTime > BolkonskyModeDuration) { BolkonskyModeOn = false; CurrentMorale = unit.GetParams().baseMorale; unit.SetHP(1); if (unit.GetOwner() == UnitOwner.PLAYER) { transform.Find("SpritePlayer/flag").gameObject.SetActive(false); } else { transform.Find("SpriteEnemy/flag").gameObject.SetActive(false); } //unit.soldierSprite.SwitchImage(unit.soldierSprite.runSprite); } } }