// =========================================== protected void Init() { unitCharacter = gameObject.GetComponent <UnitCharacter>(); unitMove = gameObject.GetComponent <UnitMove>(); _AllTiles = GameObject.FindGameObjectsWithTag("Terrain Tile"); turnManager = FindObjectOfType <TurnManager>(); }
//Move to random directions and avoid colliding with the wall and look for enemies private void Patrol() { bool sweepResult = false; if (_units[0]._rigidbody.SweepTest(_units[0]._transform.forward, out RaycastHit hit, _targetRange)) { if (hit.collider.TryGetComponent(out Character character)) { target = character.GetTarget(); if (character._units.Count > _units.Count || character is PlayerCharacter) { _state = State.Flee; return; } else { _state = State.Follow; return; } } if (hit.collider.CompareTag("Boundary")) { sweepResult = true; } } if (moveRotation == Vector3.zero || sweepResult) { moveRotation.y = Random.Range(0, 180); _transform.rotation = Quaternion.Euler(moveRotation); } _transform.position += _transform.forward * moveSpeed * Time.deltaTime; }
//===================================================== #region Basic Functionality public void Init() { allTiles = GameObject.FindGameObjectsWithTag("Terrain Tile"); halfUnitHeight = gameObject.GetComponent <Collider>().bounds.extents.y; unitCharacter = gameObject.GetComponent <UnitCharacter>(); originalRotation = transform.rotation; }
public static void AddUnitToGame(string unitTag, UnitCharacter unitCharacter) { var unitToAdd = Tuple.Create(unitTag, unitCharacter); if (!AllUnits.Contains(unitToAdd)) { _LivingUnits++; AllUnits.Add(unitToAdd); } }
//Destroy a unit and check if the game is won or lost public void DestroyUnit(UnitCharacter unit) { _units.Remove(unit); Destroy(unit._gameobject); if (_units.Count == 0 && _gameobject) { Destroy(_gameobject); FindObjectOfType <GameController>().CheckWin(this); } }
public void DealDamage(UnitCharacter enemy) { var actualDamageDealt = abilityDamage - enemy._DamageResistance; if (actualDamageDealt > 0) { enemy._CurrentHealth -= actualDamageDealt; } if (enemy._CurrentHealth <= 0) { enemy._CurrentHealth = 0; } }
//Update the levels of all the units of the character having lower level than the unit that ate another unit private bool ChainReact(UnitCharacter unit) { if (unit.level > _unitMaterials.Length - 1) { DestroyUnit(unit); return(false); } else { foreach (UnitCharacter uni in _units) { if (uni.level < unit.level - 1) { uni.level++; UpdateMaterial(uni); } } return(true); } }
//Eat a unit and multiply and cause a chain reaction public void Eat(UnitCharacter unit, UnitCharacter target) { if (!target) { return; } unit.level++; if (ChainReact(unit)) { UpdateMaterial(unit); UnitCharacter newUnit = Instantiate(unit._gameobject, _transform).GetComponent <UnitCharacter>(); _units.Add(newUnit); newUnit.level = unit.level; UpdateMaterial(newUnit); } target._parent.DestroyUnit(target); }
//Follow an enemy when found and try to eat them private void Follow() { if (!target) { _state = State.Patrol; return; } Vector3 moveDirection = target._transform.position - _transform.position; if (moveDirection.magnitude < _targetMaxRange) { _transform.rotation = Quaternion.LookRotation(moveDirection, Vector3.up); } else { target = null; _state = State.Patrol; return; } _transform.position += _transform.forward * moveSpeed * Time.deltaTime; }
//Eat the collided unit and multiply/chain react private void Eat(UnitCharacter unit) { _parent.Eat(this, unit); }
public void Update() { currentUnit = turnManager._CurrentlyActiveUnit; }
public void UpdateCurrentCharacter(UnitCharacter currentUnit) { characterTakingTurn = currentUnit; UpdateStatBlock(); }
//Change the material of a unit based on it's level protected void UpdateMaterial(UnitCharacter unit) { unit._renderer.sharedMaterial = _unitMaterials[unit.level]; }