void FindRock() { currentRock = null; Grid grid = FindObjectOfType <Grid>(); Node HutNode = grid.NodeFromWorldPoint(transform.position); foreach (GameObject rock in GameObject.FindGameObjectsWithTag("Rock")) { Node rockNode = grid.NodeFromWorldPoint(rock.transform.position); if (rockNode.gridX <= HutNode.gridX + Radius && rockNode.gridX >= HutNode.gridX - Radius && rockNode.gridY <= HutNode.gridY + Radius && rockNode.gridY >= HutNode.gridY - Radius) { RockScript rs = rock.GetComponent <RockScript>(); ObjectOnGrid oog = rock.GetComponent <ObjectOnGrid>(); if (rs.available && oog.placed) { currentRock = rock; rs.available = false; return; } } } }
/// <summary> /// Sent when an incoming collider makes contact with this object's /// collider (2D physics only). /// </summary> /// <param name="other">The Collision2D data associated with this collision.</param> void OnCollisionEnter2D(Collision2D other) { //Debug.Log(other.gameObject + " " + gameObject.name); if (other.gameObject.CompareTag("DeathCollider")) { FindObjectOfType <GameController>().onPlayerDie(playerNumber); if (gameObject) { Camera.main.GetComponent <Camera2D>().RemoveFocus(this.GetComponent <GameEye2D.Focus.F_Transform>()); AudioSource.PlayClipAtPoint(deathClip, transform.position, 10f); Destroy(gameObject); } return; } RockScript rockScript = other.gameObject.GetComponent <RockScript>(); if (!rockScript || rockScript.currentState != RockScript.state.PUSHED) { return; } Debug.Log(other.rigidbody.velocity); if (!stunned) { stunned = true; StartCoroutine("Stun"); } }
public void CopyAndForce(GameObject go, int netIndex) { if (GlobalData.GetInstance().gameMode == GameMode.OnlineMode) { if (netIndex >= RockNetPrefab.Length) { Debug.LogError("CopyAndForce -> netIndex is wrong!"); return; } int rockId = int.Parse(Network.player.ToString()); GameObject rockPrefab = RockNetPrefab[netIndex]; GameObject go1 = Network.Instantiate(rockPrefab, go.transform.position, go.transform.rotation, rockId) as GameObject; RockNet r = (RockNet)go1.GetComponent("RockNet"); r.AddForce(); r.BenginDestoryColne(); } else { GameObject go1 = Instantiate(go, go.transform.position, go.transform.rotation) as GameObject; RockScript r = (RockScript)go1.GetComponent("RockScript"); r.AddForce(); r.BenginDestoryColne(); } }
bool Punch() { RockScript rockScript; if (grabbedRock) { rockScript = grabbedRock; grabbedRock = null; } else { rockScript = selectedRock; setSelectedRock(null); } if (!rockScript) { return(false); } rockScript.getPushed(getAimingDirection()); if (grounded) { anim.SetTrigger("Punch"); } else { anim.SetTrigger("Punch_air"); } return(true); }
/// <summary> /// 对所有子物体施加力 /// </summary> public void ForceAll() { if (GlobalData.GetInstance().gameMode == GameMode.OnlineMode) { for (int i = 0; i < ChilderRocks.Length; i++) { RockNet r = (RockNet)ChilderRocks[i].GetComponent("RockNet"); ChilderRocks[i].SetActive(false); int rockId = int.Parse(Network.player.ToString()); GameObject rockPrefab = RockNetPrefab[i]; GameObject go1 = Network.Instantiate(rockPrefab, ChilderRocks[i].transform.position, ChilderRocks[i].transform.rotation, rockId) as GameObject; r = (RockNet)go1.GetComponent("RockNet"); r.AddForce(); r.BenginDestoryColne(); } } else { for (int i = 0; i < ChilderRocks.Length; i++) { RockScript r = (RockScript)ChilderRocks[i].GetComponent("RockScript"); r.AddForce(); r.BenginDestoryColne(); } } }
void HighlightSelectedRock() { if (grabbedRock) { setSelectedRock(null); return; } RockScript script = null; RaycastHit2D frontRayHit = Physics2D.Raycast(rayOrigin.position, aimingDirection, 2f, groundLayer); if (frontRayHit) { script = frontRayHit.collider.GetComponent <RockScript>(); if (script) { setSelectedRock(script); shouldGrab = false; return; } } RaycastHit2D backRayHit = Physics2D.Raycast(rayOrigin.position, -aimingDirection, 10f, groundLayer); if (backRayHit) { script = backRayHit.collider.GetComponent <RockScript>(); if (script) { setSelectedRock(script); shouldGrab = true; return; } } setSelectedRock(null); }
void Start() { rockScript = gameObject.GetComponent <RockScript>(); animator = gameObject.GetComponent <AnimationController2D>(); rb2d = GetComponent <Rigidbody2D>(); sizeX = transform.localScale.x; hasShot = false; switch (shotType) { case "air": animator.setAnimation("mostlyBlank"); break; case "water": animator.setAnimation("waterIdle"); break; case "fire": animator.setAnimation("fireIdle"); break; case "plasma": animator.setAnimation("plasmaIdle"); break; } }
/// <summary> /// Open rock radial dial, store rock /// </summary> /// <param name="rock">Rock selected</param> public void Open(RockScript rock) { _rock = rock; _rockText.text = rock.RockType.ToString(); DoUpdateChecks(); gameObject.SetActive(true); }
protected void InteractWithRock(RockScript rock) { float ratio = 1; if ((this.owner == 1 && rock.Sens == -1) || (this.owner == 0 && rock.Sens == 1)) { ratio = 0.5f; } rock.pv -= GetRatio() * this.maxDamage * this.ratioToRocks * ratio; }
protected override void Enemy_Attack() { if (AttackCooldown + AttackTiming < Time.time) { Animator_Enemy.SetBool("isAttacking", true); AttackCooldown = Time.time; GameObject Rock = Instantiate(RockAttack, gameObject.transform.position, transform.rotation); RockScript rock = Rock.GetComponent <RockScript>(); rock.SetTrajectory((PlayerChar.transform.position - gameObject.transform.position).normalized); base.Enemy_Attack(); } }
bool Grab() { RockScript rockScript = selectedRock; if (rockScript && rockScript.getGrabbed(this)) { grabbedRock = rockScript; return(true); } return(false); }
public void ShowRockOptions(RockScript rock) { CloseMenu(); if (rock == null) { return; } if (rock.RockType != RockScript.Type.SolidRock) { MenuOpen = true; _rockMenu.GetComponent <RockOptionsMenu>().Open(rock); } }
bool Grab() { RockScript rockScript = selectedRock; /* * if (rockScript && rockScript.getGrabbed(this)) * { * grabbedRock = rockScript; * return true; * } */ return(false); }
private void Awake() { if (instance == null) { instance = this; } isAlive = true; score = 0; throwStoneButton = GameObject.FindGameObjectWithTag("FlapButton").GetComponent <Button>(); throwStoneButton.onClick.AddListener(() => RollTheRock()); SetCamsX(); }
bool Punch() { RockScript rockScript; if (grabbedRock) { rockScript = grabbedRock; grabbedRock = null; } else { rockScript = selectedRock; if (rockScript) { Vector2 rockPos = new Vector2(rockScript.transform.position.x, rockScript.transform.position.y); //Debug.DrawRay(rockPos + rockScript.c2d.offset, getAimingDirection(), Color.red, 5f); if (Physics2D.Raycast(rockPos + rockScript.c2d.offset, getAimingDirection(), rockScript.isBig ? 2f : 1f, groundLayer)) { rockScript.destroyOther = false; } } setSelectedRock(null); } if (!rockScript) { return(false); } Physics2D.IgnoreCollision(GetComponent <Collider2D>(), rockScript.c2d); rockScript.getPushed(getAimingDirection()); if (grounded) { anim.SetTrigger("Punch"); } else { anim.SetTrigger("Punch_air"); } return(true); }
bool Grab() { RockScript rockScript = selectedRock; if (rockScript && rockScript.getGrabbed(this)) { // if we have supercharge, charge the next block we grab if (superPunchChargeTrigger) { rockScript.ChargeBlock(); superPunchChargeTrigger = false; } grabbedRock = rockScript; return(true); } return(false); }
void setSelectedRock(RockScript rock) { if (rock == selectedRock) { return; } if (selectedRock) { selectedRock.highlighted = 0; } if (rock) { selectedRock = rock; selectedRock.highlighted = playerNumber; } else { selectedRock = null; } }
/// <summary> /// 对所有子物体有一定概率施加力. /// </summary> public void ForcePossible() { float rand = Random.value; if (GlobalData.GetInstance().gameMode == GameMode.OnlineMode) { for (int i = 0; i < ChilderRocks.Length; i++) { //Debug.Log("5555555555555555555555"+ChilderRocks.Length+"rand"+rand); RockNet r = (RockNet)ChilderRocks[i].GetComponent("RockNet"); if (rand < r.probability) { ChilderRocks[i].SetActive(false); int rockId = int.Parse(Network.player.ToString()); GameObject rockPrefab = RockNetPrefab[i]; GameObject go1 = Network.Instantiate(rockPrefab, ChilderRocks[i].transform.position, ChilderRocks[i].transform.rotation, rockId) as GameObject; r = (RockNet)go1.GetComponent("RockNet"); r.AddForce(); r.BenginDestoryColne(); } } } else { for (int i = 0; i < ChilderRocks.Length; i++) { //Debug.Log("5555555555555555555555"+ChilderRocks.Length+"rand"+rand); RockScript r = (RockScript)ChilderRocks[i].GetComponent("RockScript"); if (rand < r.probability) { r.AddForce(); r.BenginDestoryColne(); } } } }
public bool CanMineTarget(RockScript Target) { if (Target == null) { return(false); } int Level = (int)WorldController.GetWorldController._miningLevel; switch (Target.RockType) { case RockScript.Type.Dirt: return(true); case RockScript.Type.LooseRock: return(Level >= 1); case RockScript.Type.HardRock: return(Level >= 2); } return(false); }
/// <summary> /// Checks all tiles, and ajusts walls /// </summary> static public void RockProximty() { for (int x = 0; x < Map.GridXSize_; x++) { for (int y = 0; y < Map.GridYSize_; y++) { Tile tile = StaticMapInfo.Map.GetTileAtPos(x, y); if (tile.tag == "RockTile") { RockScript tileRockSript = tile.GetComponent <RockScript>(); tileRockSript.RockNorth = StaticMapInfo.isWall(x, y + 1); tileRockSript.RockNorthEast = StaticMapInfo.isWall(x + 1, y + 1); tileRockSript.RockEast = StaticMapInfo.isWall(x + 1, y); tileRockSript.RockSouthEast = StaticMapInfo.isWall(x + 1, y - 1); tileRockSript.RockSouth = StaticMapInfo.isWall(x, y - 1); tileRockSript.RockSouthWest = StaticMapInfo.isWall(x - 1, y - 1); tileRockSript.RockWest = StaticMapInfo.isWall(x - 1, y); tileRockSript.RockNorthWest = StaticMapInfo.isWall(x - 1, y + 1); } } } }
/// <summary> /// 每个子物体根据概率决定是否复制自己并施加力 /// </summary> public void CopyAndForceAll() { if (GlobalData.GetInstance().gameMode == GameMode.OnlineMode) { if (ChilderRocks == null) { ScreenLog.LogWarning("CopyAndForceAll -> ChilderRocks is null"); return; } for (int i = 0; i < ChilderRocks.Length; i++) { float rand = Random.value; //Debug.Log("5555555555555555555555"+ChilderRocks.Length+"rand"+rand); //RockNet r = (RockNet)ChilderRocks[i].GetComponent("RockNet"); RockScript r = (RockScript)ChilderRocks[i].GetComponent("RockScript"); if (rand < r.probability) { copyCount++; CopyAndForce(ChilderRocks[i], i); } } } else { for (int i = 0; i < ChilderRocks.Length; i++) { float rand = Random.value; //Debug.Log("5555555555555555555555"+ChilderRocks.Length+"rand"+rand); RockScript r = (RockScript)ChilderRocks[i].GetComponent("RockScript"); if (rand < r.probability) { copyCount++; CopyAndForce(ChilderRocks[i], i); } } } }
void FindNearestRock() { currentRock = null; float dist = float.MaxValue; Grid grid = FindObjectOfType <Grid>(); Node HutNode = grid.NodeFromWorldPoint(transform.position); foreach (GameObject rock in GameObject.FindGameObjectsWithTag("Rock")) { Node rockNode = grid.NodeFromWorldPoint(rock.transform.position); if (rockNode.gridX <= HutNode.gridX + Radius && rockNode.gridX >= HutNode.gridX - Radius && rockNode.gridY <= HutNode.gridY + Radius && rockNode.gridY >= HutNode.gridY - Radius) { RockScript rs = rock.GetComponent <RockScript>(); ObjectOnGrid oog = rock.GetComponent <ObjectOnGrid>(); if (rs.available && oog.placed) { float currRockDist = Mathf.Sqrt(Mathf.Pow(rockNode.gridX - HutNode.gridX, 2) + Mathf.Pow(rockNode.gridY - HutNode.gridY, 2)); if (currRockDist < dist) { currentRock = rock; dist = currRockDist; } } } } if (currentRock != null) { RockScript rs = currentRock.GetComponent <RockScript>(); rs.available = false; } }
Vector2 findSpawnPoint() { List <Vector3> available = new List <Vector3>(); foreach (GameObject rockObject in GameObject.FindGameObjectsWithTag("Rock")) { RockScript rock = rockObject.GetComponent <RockScript>(); if (!rock) { continue; } Vector2 rockTop = rock.getTop(); RaycastHit2D hit = Physics2D.Raycast(rockTop, Vector2.up, 2.5f, groundLayerMask); if (!hit.collider) { available.Add(rockTop); } else { if (hit.collider.gameObject.layer == 12) { Debug.DrawRay(hit.point, Vector2.up, Color.red, 5f); } } } if (available.Count == 0) { return(Vector3.zero); } Vector2 pos = available[Random.Range(0, available.Count)]; Debug.DrawRay(pos, Vector2.up, Color.cyan, 5f); return(pos); // available[Random.Range(0, available.Count)]; }
float FindLevel() { List <Vector3> available = new List <Vector3>(); float highestLevel = -100, secondLevel = -100; foreach (GameObject rockObject in GameObject.FindGameObjectsWithTag("Rock")) { RockScript rock = rockObject.GetComponent <RockScript>(); if (!rock) { continue; } if (rock.currentState != RockScript.state.FIXED) { continue; } Vector2 rockTop = rock.getTop(); RaycastHit2D hit = Physics2D.Raycast(rockTop, Vector2.up, 2.5f, groundLayerMask); if (!hit.collider) { if (rock.transform.position.y > highestLevel) { highestLevel = rock.transform.position.y; } else if (rock.transform.position.y == highestLevel) { secondLevel = rock.transform.position.y; } else if (rock.transform.position.y >= secondLevel) { secondLevel = rock.transform.position.y; } } } return(secondLevel); }
void Start() { attachedRock = GetComponent <RockScript>(); }
public void ChildDeath(RockScript child) { isChildDead = true; }
public UnitTask CreateTask(UnitTask.TaskType t, Vector3 pos, GameObject Data) { UnitTask newTask = null; switch (t) { case UnitTask.TaskType.Mine: RockScript Rock = Data.GetComponentInParent <RockScript>(); if (CanMineTarget(Rock)) { newTask = new UnitTask { _location = pos, _taskType = UnitTask.TaskType.Mine, _targetRock = Rock, _requiredTool = Unit.UnitTool.MiningTool, _taskDescription = "Mining " + Rock.RockType }; } break; case UnitTask.TaskType.Pickup: Ore O = Data.GetComponent <Ore>(); newTask = new UnitTask { _location = pos, _taskType = UnitTask.TaskType.Pickup, _itemToPickUp = Data, _itemType = (O != null) ? UnitTask.ItemType.Ore : UnitTask.ItemType.EnergyCrystal, _taskDescription = (O != null) ? "Transporting an Ore" : "Transporting an Energy crystal", _requiredTool = Unit.UnitTool.none }; break; case UnitTask.TaskType.Walk: newTask = new UnitTask { _location = pos, _taskType = UnitTask.TaskType.Walk, _taskDescription = "Walking to location", _requiredTool = Unit.UnitTool.none }; break; case UnitTask.TaskType.Attack: Monster tempMonster = Data.GetComponent <Monster>(); newTask = new UnitTask { _location = pos, _taskType = UnitTask.TaskType.Attack, _requiredTool = Unit.UnitTool.Weapon, _taskDescription = "Attacking " + tempMonster._type, _targetMonster = Data.GetComponent <Monster>() }; break; case UnitTask.TaskType.flameTarget: MushroomCluster mushroom = Data.GetComponentInParent <MushroomCluster>(); if (mushroom == null) { return(null); } newTask = new UnitTask { _location = pos, _taskType = UnitTask.TaskType.flameTarget, _requiredTool = Unit.UnitTool.FlameThrower, _taskDescription = "Burning things", _targetMushroom = mushroom }; break; case UnitTask.TaskType.Reinforce: break; case UnitTask.TaskType.Build: Building tempBuilding = Data.GetComponentInParent <Building>(); newTask = new UnitTask { _location = pos, _taskType = UnitTask.TaskType.Build, _targetBuilding = Data.GetComponentInParent <Building>(), _requiredTool = Unit.UnitTool.Hammer, _taskDescription = "Building a " + tempBuilding.name }; break; case UnitTask.TaskType.GetTool: newTask = new UnitTask { _location = pos, _taskType = UnitTask.TaskType.GetTool, _taskDescription = "Getting " + RadialMenuScript.instance.NewTool.ToString(), _requiredTool = RadialMenuScript.instance.NewTool }; break; case UnitTask.TaskType.RefillOxygen: Building closestOxyGen = null; foreach (Building building in WorldController.GetWorldController._buildings) { if (building.tag == TagLibrary.GEN_TAG && building._Built) { if (closestOxyGen == null || Vector3.Distance(Data.transform.position, building.transform.position) < Vector3.Distance(Data.transform.position, closestOxyGen.transform.position)) { closestOxyGen = building; } } } if (closestOxyGen == null) { return(null); } newTask = new UnitTask { _location = closestOxyGen.transform.position, _taskType = UnitTask.TaskType.RefillOxygen, _taskDescription = "Refilling Oxygen", _targetBuilding = closestOxyGen }; break; case UnitTask.TaskType.RefillEnergy: Building tempBuidling = Data.GetComponent <Building>(); newTask = new UnitTask { _location = pos, _taskType = UnitTask.TaskType.RefillEnergy, _targetBuilding = tempBuidling, _taskDescription = "Refilling " + tempBuidling.name + " energy" }; break; case UnitTask.TaskType.ClearRubble: RubbleScript tempRubble = Data.GetComponentInParent <RubbleScript>(); if (tempRubble == null) { return(null); } newTask = new UnitTask { _location = tempRubble.transform.position, _taskType = UnitTask.TaskType.ClearRubble, _targetRubble = tempRubble, _requiredTool = Unit.UnitTool.Shovel, _taskDescription = "Clearing rubble" }; break; case UnitTask.TaskType.GetInVehicle: Vehicle tempVehicle = Data.GetComponent <Vehicle>(); newTask = new UnitTask { _location = pos, _taskType = UnitTask.TaskType.GetInVehicle, _targetVehicle = tempVehicle, _taskDescription = "Entering vehicle" }; break; case UnitTask.TaskType.RechargeVehicle: newTask = new UnitTask { _location = pos, _taskType = UnitTask.TaskType.RechargeVehicle, _taskDescription = "Recharging vehicle" }; break; case UnitTask.TaskType.Idle: case UnitTask.TaskType.none: default: Debug.LogError("Invalid Task for Create Task: " + t.ToString()); break; } if (newTask == null || !newTask.IsValid()) { return(null); } return(newTask); }
// Update is called once per frame void Update() { if (citizen == null) { return; } switch (state) { case States.GoingToWorkplace: if (ArrivedAtTarget(mhc.InitialPosition)) { state = States.Available; } break; case States.Available: if (hasWorkToDo) { return; } if (!noRocksInArea) { Work(); } else { if (currentFindingTime < FindingTime) { currentFindingTime += Time.deltaTime; } else { currentFindingTime = 0f; Work(); } } break; case States.PathFinding: if (currentRock == null) { ResetWork(); } if (ArrivedAtTarget(currentRock)) { AudioSource audio = currentRock.GetComponent <AudioSource>(); audio.volume = sm.volume; audio.Play(); state = States.Working; //Debug.Log("Arived at the rock"); } break; case States.Working: if (currentRock == null) { ResetWork(); } if (currentMiningTime < MiningTime) { currentMiningTime += Time.deltaTime; } else { RockScript ts = currentRock.GetComponent <RockScript>(); StoneGained = ts.Mine(StoneAccumulation); ts.CutDownIfEmpty(); RockCutted(); } break; case States.CarryingGoods: if (ArrivedAtTarget(mhc.InitialPosition)) { GoodsArrived(); state = States.Available; hasWorkToDo = false; } break; default: break; } }
// Update is called once per frame void Update() { if (Health <= 0) { if (!dead) { WorldController.GetWorldController._levelStatsController.MosterKilled(); _aiSound.enabled = false; } dead = true; } if (!dead) { _crystalList = _theWorldControllor._energyCrystals; _buildingList = _theWorldControllor._buildings; _UnitList = _theWorldControllor._workers; //main switch switch (_currentMonsterState) { case MonsterState.wondering: if (_navAgent.remainingDistance < 0.1f && !_navAgent.pathPending && _wonderTimer <= 0) { _navAgent.destination = new Vector3(Random.Range(transform.position.x - 20, transform.position.x + 20), Random.Range(transform.position.y - 20, transform.position.y + 20), Random.Range(transform.position.z - 20, transform.position.z + 20)); _animator.SetBool("Walking", true); _animator.SetBool("Attacking", false); _wonderTimer = 5; } else if (_navAgent.remainingDistance < 0.1f && !_navAgent.pathPending && _wonderTimer > 0) { _wonderTimer -= Time.deltaTime; _animator.SetBool("Walking", false); } // CheckWhatsClosest(true,false,30); CheckWhatsClosestMk2(true, false, false, false, 30, true); break; case MonsterState.attackingBuilding: _navAgent.SetDestination(_closestBuilding.transform.position); _animator.SetBool("Walking", true); if (Vector3.Distance(_closestBuilding.transform.position, transform.position) < 5f && !_navAgent.pathPending) { _animator.SetBool("Walking", false); _animator.SetBool("Attacking", true); if (_attackTimer <= 0) { // Debug.Log("Nom!"); _closestBuilding.GetComponent <Building>().Health -= _attackDamage; _aiSound.Attack(); _attackTimer = 1.8f; } else { _attackTimer -= Time.deltaTime; } } //CheckWhatsClosest(true,false,30); CheckWhatsClosestMk2(true, false, false, false, 30, true); break; case MonsterState.attackingUnit: if (Vector3.Distance(_closestUnit.transform.position, transform.position) < 3) { _navAgent.speed = _speed; _animator.SetBool("Walking", false); _animator.SetBool("Attacking", true); if (_attackTimer <= 0f) { // Debug.Log("Nom!"); _closestUnit.GetComponent <Unit>().TakeDamage(_attackDamage); _aiSound.Attack(); _attackTimer = 1.8f; } else { _attackTimer -= Time.deltaTime; } } else { _navAgent.SetDestination(_closestUnit.transform.position); _animator.SetBool("Walking", true); } // Debug.Log("Remaining distance: " + _navAgent.remainingDistance + " Distance too unit: " + Vector3.Distance(_closestUnit.transform.position, transform.position) + ", is path pending: " + _navAgent.pathPending); //Debug.Log((_navAgent.remainingDistance <= 3) + " " + (Vector3.Distance(_closestUnit.transform.position, transform.position) > 5) + " " + (!_navAgent.pathPending)); if (_navAgent.remainingDistance <= 3 && Vector3.Distance(_closestUnit.transform.position, transform.position) > 5 && Vector3.Distance(_closestUnit.transform.position, transform.position) < 28) { _currentMonsterState = MonsterState.BreakWall; // Debug.Log("Change to break wall"); break; } if (_closestUnit == null) { _currentMonsterState = MonsterState.wondering; } if (Vector3.Distance(_closestUnit.transform.position, transform.position) > 20) { _currentMonsterState = MonsterState.wondering; } // CheckWhatsClosest(true,false,30); CheckWhatsClosestMk2(true, false, false, false, 30, true); break; case MonsterState.eating: _navAgent.SetDestination(_closestEnergyCrystal.transform.position); _animator.SetBool("Walking", true); if (_navAgent.remainingDistance < 0.1f && !_navAgent.pathPending) { _animator.SetBool("Walking", false); _theWorldControllor._energyCrystals.Remove(_closestEnergyCrystal); Destroy(_closestEnergyCrystal.transform.gameObject); _eatenCrystals++; _currentMonsterState = MonsterState.wondering; } // CheckWhatsClosest(true,false,30); CheckWhatsClosestMk2(true, false, false, false, 30, true); break; case MonsterState.BreakWall: //ray cast to closest worker _ray = new Ray(transform.position, _closestUnit.transform.position - transform.position); // Debug.DrawRay(transform.position, _closestUnit.transform.position - transform.position); if (Physics.Raycast(_ray, out _hit)) { if (_hit.transform.tag == "RockTile") { if (_hit.transform.GetComponentInParent <RockScript>().RockType != RockScript.Type.SolidRock) { _targetRock = _hit.transform.GetComponentInParent <RockScript>(); _navAgent.SetDestination(_targetRock.transform.position); } } } if (_targetRock == null) { _currentMonsterState = MonsterState.wondering; } else { if (Vector3.Distance(transform.position, _targetRock.transform.position) < 6) { _targetRock.DistroyRock(); _targetRock = null; _currentMonsterState = MonsterState.wondering; } } break; } } else { WorldController.GetWorldController._monsters.Remove(this); _navAgent.ResetPath(); _navAgent.enabled = false; _animator.SetBool("Dead", true); _animator.SetBool("Walking", false); _animator.SetBool("Attacking", false); _animator.SetBool("False", false); Destroy(GetComponent <BoxCollider>()); Destroy(GetComponent <SelectableObject>()); } }
void SelectUI() { if (!HasSelection()) { return; } SelectionData Single = CurrentSelectionObjects[0]; if (Single.IsWorker()) { if (_hit.transform.tag == TagLibrary.HQ_TAG) { //RadialMenuScript.instance.ShowToolOptions(Single._Worker, _hit.transform.position); if (_hit.transform.GetComponent <Tile>() != null || _hit.transform.GetComponent <HQTileTagScript>() != null) { ExecuteOrderOnAll(UnitTask.TaskType.Walk); } } else if (_hit.transform.tag == TagLibrary.VEHICLE_TAG) { if (!_hit.transform.GetComponent <Vehicle>().GetOccupied()) { RadialMenuScript.instance.ShowEmptyVehicleOptions(Single._Worker, _hit.transform.GetComponent <Vehicle>()); } } else if (_hit.transform.tag == TagLibrary.WORKER_TAG) { Worker worker = _hit.transform.gameObject.GetComponentInParent <Worker>(); List <Worker> workers = new List <Worker>(); for (int i = 0; i < CurrentSelectionObjects.Count; i++) { workers.Add(CurrentSelectionObjects[i]._Worker); } RadialMenuScript.instance.ShowWorkerOptions(workers, worker); } else { ExecuteOrderOnAll(UnitTask.TaskType.Walk); } } else { switch (_hit.transform.tag) { case TagLibrary.ROCK_TAG: RockScript rock = _hit.transform.gameObject.GetComponentInParent <RockScript>(); RadialMenuScript.instance.ShowRockOptions(rock); break; case TagLibrary.RUBBLE_TAG: RubbleScript rubble = _hit.transform.gameObject.GetComponentInParent <RubbleScript>(); RadialMenuScript.instance.ShowRubbleOptions(rubble); break; case TagLibrary.MONSTER_TAG: Monster monster = _hit.transform.GetComponentInParent <Monster>(); RadialMenuScript.instance.ShowEnemyOptions(monster); break; case TagLibrary.HQ_TAG: HQ hq = _hit.transform.GetComponentInParent <HQ>(); RadialMenuScript.instance.ShowHQOptions(hq); break; case TagLibrary.OUTPOST_TAG: Outpost outpost = _hit.transform.GetComponentInParent <Outpost>(); RadialMenuScript.instance.ShowOutpostOptions(outpost); break; case TagLibrary.GARAGE_TAG: Garage garage = _hit.transform.GetComponentInParent <Garage>(); RadialMenuScript.instance.ShowGarageOptions(garage); break; case TagLibrary.GEN_TAG: case TagLibrary.SKIP_TAG: case TagLibrary.BLOCK_TAG: case TagLibrary.TURRET_TAG: case TagLibrary.POWERGEN_TAG: Building building = _hit.transform.GetComponentInParent <Building>(); RadialMenuScript.instance.ShowBuildingOptions(building); break; case TagLibrary.ORE_TAG: Ore ore = _hit.transform.GetComponentInParent <Ore>(); RadialMenuScript.instance.ShowResourceOptionsOre(ore); break; case TagLibrary.ENERGYCRYSTAL_TAG: EnergyCrystal energyCrystal = _hit.transform.GetComponentInParent <EnergyCrystal>(); RadialMenuScript.instance.ShowResourceOptionsEnergyCrystal(energyCrystal); break; case TagLibrary.VEHICLE_TAG: Vehicle vehicle = _hit.transform.GetComponent <Vehicle>(); if (vehicle.GetOccupied()) { RadialMenuScript.instance.ShowVehicleOptions(_hit.transform.GetComponent <Vehicle>()); } else { RadialMenuScript.instance.ShowEmptyVehicleOptions(null, _hit.transform.GetComponent <Vehicle>()); } break; case TagLibrary.BURN_TAG: MushroomCluster mushroomCluster = _hit.transform.GetComponentInParent <MushroomCluster>(); RadialMenuScript.instance.ShowMushroomOptions(mushroomCluster); break; } } if (!Single.IsWorker()) { ClearSelectedObjects(false); } SetMode(CurrentSelectionMode.RadialMenu); }
void HighlightSelectedRock() { if (grabbedRock) { setSelectedRock(null); return; } RockScript script = null; RaycastHit2D frontRayHit = Physics2D.Raycast(rayOrigin.position, aimingDirection, 2f, groundLayer); if (frontRayHit) { script = frontRayHit.collider.GetComponent <RockScript>(); if (script) { setSelectedRock(script); shouldGrab = false; return; } } else { frontRayHit = Physics2D.Raycast(rayOrigin.position - Vector3.up, aimingDirection, 2f, groundLayer); if (frontRayHit) { script = frontRayHit.collider.GetComponent <RockScript>(); if (script) { setSelectedRock(script); shouldGrab = false; return; } } } RaycastHit2D backRayHit = Physics2D.Raycast(rayOrigin.position, -aimingDirection, 10f, groundLayer); if (backRayHit) { script = backRayHit.collider.GetComponent <RockScript>(); if (script) { setSelectedRock(script); shouldGrab = true; return; } } else { backRayHit = Physics2D.Raycast(rayOrigin.position - Vector3.up, -aimingDirection, 10f, groundLayer); if (backRayHit) { script = backRayHit.collider.GetComponent <RockScript>(); if (script) { setSelectedRock(script); shouldGrab = true; return; } } } if (selectedRock) { if (onlyOnce) { selectedRockTime = Time.time; onlyOnce = false; } if (selectedRockTime + selectedRockTimer > Time.time) { setSelectedRock(selectedRock); } else { setSelectedRock(null); } return; } setSelectedRock(null); }