public DSeeEvilClone() { henry = GameObject.FindGameObjectWithTag("Player"); evilClone = GameObject.FindGameObjectWithTag("Enemy"); pathFollowing = henry.GetComponent <PathFollowing>(); flee = henry.GetComponent <Flee> (); }
public FollowPath(AgentUnit agent, Vector3[] path, FollowT type, Action <bool> callback) : base(agent, callback) { empty = new GameObject(); if (agent == null) { Debug.Log(agent); Debug.LogError("Follow path en unidad muerta "); } else { empty.transform.parent = agent.gameObject.transform; } if (type == FollowT.STAY) { pathF = empty.AddComponent <PathFollowingAdvanced>(); } else { pathF = empty.AddComponent <PathFollowing>(); pathF.type = type; } pathF.SetNPC(agent); pathF.SetPath(path); pathF.visibleRays = true; pathF.maxAccel = 700f; }
public Patrolling() { henry = GameObject.FindGameObjectWithTag("Player"); currentPoint = 0; canSeeEvilClone = new CanSeeEvilClone(); pathFollowing = henry.GetComponent <PathFollowing>(); }
private PathFollowing pathFollowing; // the steering behaviour void Awake() { seeker = GetComponent <Seeker>(); pathFollowing = GetComponent <PathFollowing>(); pathFollowing.enabled = false; //pathFollowing.wayPointReachedRadius = 3f; }
private void pathFollowingToolStripMenuItem_Click(object sender, EventArgs e) { var world = GameWorld.Instance; foreach (var entity in world.Entities) { if (pathFollowingToolStripMenuItem.Checked) { Location goal = new Location(world.Random.Next(5, (int)world.Width - 5), world.Random.Next(5, (int)world.Height - 5)); BaseSteering behaviour; if (Settings.Instance.UseTimeSlicedNavigation) { behaviour = new PathFollowingTimeSliced(goal); } else { behaviour = new PathFollowing(goal); } entity.AddBehaviour(behaviour); } else { if (Settings.Instance.UseTimeSlicedNavigation) { entity.RemoveBehaviour(typeof(PathFollowingTimeSliced)); } else { entity.RemoveBehaviour(typeof(PathFollowing)); } } } }
// Update is called once per frame private void Awake() { if (instance == null) { instance = this; } else if (instance != this) { Destroy(gameObject); } }
// Use this for initialization protected override void Initialize() { EnemyAni = gameObject.GetComponentInChildren <EnemyAnimation> (); PathScript = gameObject.GetComponent <PathFollowing> (); sound = GameObject.Find("Sound").GetComponent <Sound> (); player = GameObject.FindGameObjectWithTag("Player"); curState = FSMState.Patrol; bDead = false; health = 1; play = 0.0f; shootRate = 2.0f; }
public void Revert() { for (int i = 0; i < PlacedTiles.Count; i++) { PlacedTiles[i].go.transform.position = StaticPlacedTiles[i].go.transform.position + (new Vector3(0f, 10f, 0f)); PathFollowing p = PlacedTiles[i].go.GetComponent <PathFollowing>(); if (p != null) { p.setStateToIdle(); } } }
void ApplySelection() { agents = FindObjectsOfType <AiAgent>(); foreach (AiAgent agent in agents) { PathFollowing pathFollowing = agent.GetComponent <PathFollowing>(); if (pathFollowing != null) { pathFollowing.target = selectedTarget; pathFollowing.UpdatePath(); } } }
public DefaultMovementController(string characterName, GameObject character) { this.characterName = characterName; this.character = character; wanderingFunctions = new Wandering(this.character); pursuingFunctions = new Pursuing(this.character); pathfollowingFunctions = new PathFollowing(this.character, new ArrayList() { new Vector2(115f, 5f), new Vector2(115f, 10f), new Vector2(120f, 10f), new Vector2(120f, 5f) }, true); bouncingFunctions = new Bounce(this.character); nearbyPlayerFunctions = new NearbyTarget(this.character, targetPoint, .5f); previousLocation = character.transform.position; }
private void buttonReleasedHandler(object sender, EventArgs e) { if (levelManager.loading) { return; } ReleaseGesture gesture = (ReleaseGesture)sender; GameObject s = gesture.gameObject; if (s.name.Equals(bottomCamCanvas.name)) { PlacementUI.SetActive(false); if (activeKey != "" && database[activeKey].first.activeSelf) { if ((database[activeKey].first.tag != "PaintableBackground" || database[activeKey].first.tag == "PaintableBackground" && database[activeKey].first.GetComponent <SpriteRenderer>() != null)) { PlaceObject(lastTouchPosition); } database[activeKey].first.SetActive(false); database[activeKey].second.SetActive(false); } if (lastObjectSelected != null) { lastObjectSelected.first.transform.position = lastObjectSelected.second.transform.position + (new Vector3(0f, LevelManager.SCREEN_GAP, 0f)); PathFollowing p = lastObjectSelected.first.GetComponent <PathFollowing>(); if (p != null) { p.setStateToIdle(); } lastObjectSelected = null; } if (shouldResetKey) { activeKey = keyToReset; keyToReset = ""; shouldResetKey = false; } draggingObject = null; removed = false; dragging = false; } }
public void createPathFollow(SteeringOutput steering) { PathFollowing myPath = new PathFollowing { character = this, target = myTarget }; steering = myPath.getSteering(); if (steering != null) { linearVelocity += steering.linear * Time.deltaTime; angularVelocity += steering.angular * Time.deltaTime; } }
private string getSaveEntryString(GameObject objectToSave, GameObject staticObjectToSave) { string entry = ""; entry += staticObjectToSave.GetComponent <RFIDKey>().rfidKey + ","; Vector3 position = staticObjectToSave.transform.position; entry += position.x + "," + position.y + "," + position.z + ","; Vector3 scale = staticObjectToSave.transform.localScale; entry += scale.x + "," + scale.y + "," + scale.z + ","; PathFollowing p = objectToSave.GetComponent <PathFollowing>(); if (p != null) { entry += p.pathSpeed + ","; entry += p.pathPoints.Count + ","; for (int i = 0; i < p.pathPoints.Count; i++) { entry += p.pathPoints[i].x + "," + p.pathPoints[i].y + "," + p.pathPoints[i].z + ","; } } Jump j = objectToSave.GetComponent <Jump>(); if (j != null) { entry += j.burst + ","; } Move m = objectToSave.GetComponent <Move>(); if (m != null) { entry += m.maxSpeed[0] + "," + m.maxSpeed[1] + "," + m.maxSpeed[2] + "," + m.maxSpeed[3] + ","; } MoveHorizontalUntilCollision mh = objectToSave.GetComponent <MoveHorizontalUntilCollision>(); if (mh != null) { entry += mh.speed; } return(entry); }
private void specialRevertLogic(GameObject g, GameObject sg = null) { if (sg != null) { } PathFollowing p = g.GetComponent <PathFollowing>(); if (p != null) { p.setStateToIdle(); } CollideTrigger ct = g.GetComponent <CollideTrigger>(); if (ct != null) { ct.reset(); } TimeTrigger tt = g.GetComponent <TimeTrigger>(); if (tt != null) { tt.reset(); } DeathTrigger dt = g.GetComponent <DeathTrigger>(); if (dt != null) { dt.reset(); } Health h = g.GetComponent <Health>(); if (h != null) { h.hp = h.startHP; } StarPower sp = g.GetComponent <StarPower>(); if (sp != null) { sp.reset(); } }
public override void Activate() { State = Statusgoal.active; //create a path var Path = smartEntity.MyWorld.gameMap.PathingPipeline(smartEntity.Pos, Target.Pos, smartEntity.MyWorld.walls); PathFollowing = new PathFollowing(smartEntity, Path); //set behaviour smartEntity.Behaviours = new List <SteeringBehaviour> { PathFollowing, new WallAvoidance(smartEntity, 15), }; timer.Enabled = true; }
// Apply selected target to all agents void ApplySelection() { // FOREACH agent in agents foreach (AIAgent agent in agents) { // SET pathFollowing to agemt.GetComponent<PathFollowing>(); PathFollowing pathFollowing = agent.GetComponent <PathFollowing>(); // IF pathFollowing is not null if (pathFollowing != null) { // SET pathFollowing.target to selectedTarget pathFollowing.target = selectedTarget; // CALL pathFollowing.UpdatePath() pathFollowing.UpdatePath(); } } }
public GoToLRTA(AgentUnit agent, Vector3 target, Action <bool> callback) : base(agent, callback) { this.target = target; empty = new GameObject(); empty.transform.parent = agent.gameObject.transform; pathF = empty.AddComponent <PathFollowing>(); pathF.SetNPC(agent); pathF.path = null; pathF.visibleRays = true; pathF.maxAccel = 50f; lrta = new LRTA(); lrta.StartPath(target, agent.Cost); RequestPath(); }
/// <summary> /// Creates a new instance /// </summary> public Behaviors() { Alignment = new Alignment(); Arrive = new Arrive(); Cohesion = new Cohesion(); Evade = new Evade(); Flee = new Flee(); Hide = new Hide(); Interpose = new Interpose(); ObstacleAvoidance = new ObstacleAvoidance(); OffsetPursuit = new OffsetPursuit(); PathFollowing = new PathFollowing(); Pursuit = new Pursuit(); Seek = new Seek(); Separation = new Separation(); WallAvoidance = new WallAvoidance(); Wander = new Wander(); }
public void ApplySelection() { // FOREACH agent in agents agents = FindObjectsOfType <AIAgent>(); foreach (AIAgent agent in agents) { // SET pathFollowing = agent.Getcomponent<PathFollowing>(); PathFollowing pathFollowing = agent.GetComponent <PathFollowing>(); // IF pathFollowing is not null if (pathFollowing != null) { // SET pathFollowing.target to selectedTarget pathFollowing.target = selectedTarget; // CALL pathFollowing.UpdatePath() pathFollowing.UpdatePath(); } } }
private float elapsedTime = 0f; // time elapsed since last repathing op. // Use this for initialization void Start() { seeker = GetComponent <Seeker> (); if (seeker == null) { Debug.LogError("No seeker attached in PathFeeder"); } pathFollowingSteering = GetComponent <PathFollowing> (); if (pathFollowingSteering == null) { Debug.LogError("No PathFollowing steering attached. No steering to feed"); } pathFollowingSteering.enabled = false; // can't be enabled until a path is available // start the path computation process seeker.StartPath(this.transform.position, target.transform.position, OnPathComplete); }
// Apply selected targets to all agents void ApplySelection() { // Set Agents to FindObjectsOfType AiAgent agents = FindObjectsOfType <AIAgent>(); // FOREACH agent in agents foreach (AIAgent agent in agents) { // Set path following to agent.GetComponent<PathFollowing>(); PathFollowing pathFollowing = agent.GetComponent <PathFollowing>(); // If pathFollowing is not null if (pathFollowing != null) { //Set pathFollowing.target to selected Target pathFollowing.target = selectedTarget; // Call pathFollowing.UpdatePath() pathFollowing.UpdatePath(); } } }
// Assign target to all agents in "agentsToDirect" void AssignTargetToAllAgents(Transform target) { // Loop through all agentsToDirect foreach (var agent in agentsToDirect) { Seek s = agent.GetComponent <Seek>(); // Is seek attached to agent? if (s != null) { s.target = target; // Assign target to seek component on agent } // PathFollowing PathFollowing p = agent.GetComponent <PathFollowing>(); // Is PathFollowing attached to agent? if (p != null) { p.target = target; // Assign target to PathFollowing component on agent } } }
void Start() { pf = GetComponent <PathFollowing>(); w = GetComponent <Wander>(); player = GameObject.FindGameObjectWithTag("Player"); }
private IEnumerator processSaveEntry(string entry) { string[] delimiters = { "," }; string[] tokens = entry.Split(delimiters, StringSplitOptions.None); if (tokens.Length > 0) { int i = 0; string rfidKey = tokens[i++]; yield return(StartCoroutine(ldTime.rfidFoundCoroutine(rfidKey))); Vector3 position = new Vector3(float.Parse(tokens[i++]), float.Parse(tokens[i++]), float.Parse(tokens[i++])); Pair <GameObject, GameObject> p = ldTime.PlaceObject(position, true, true); if (p == null) { print("Could not load figure with RFID key " + rfidKey + "."); yield break; } Vector3 scale = new Vector3(float.Parse(tokens[i++]), float.Parse(tokens[i++]), float.Parse(tokens[i++])); Resize r = p.second.GetComponent <Resize>(); if (r != null) { r.setNewScale(scale); } else { p.first.transform.localScale = scale; p.second.transform.localScale = scale; } PathFollowing pf = p.first.GetComponent <PathFollowing>(); if (pf != null) { pf.pathSpeed = float.Parse(tokens[i++]); int pathPointsCount = int.Parse(tokens[i++]); for (int k = 0; k < pathPointsCount; k++) { Vector3 point = new Vector3(float.Parse(tokens[i++]), float.Parse(tokens[i++]), float.Parse(tokens[i++])); pf.pathPoints.Add(point); } } Jump j = p.first.GetComponent <Jump>(); if (j != null) { j.burst = float.Parse(tokens[i++]); } Move m = p.first.GetComponent <Move>(); if (m != null) { m.maxSpeed[0] = float.Parse(tokens[i++]); m.maxSpeed[1] = float.Parse(tokens[i++]); m.maxSpeed[2] = float.Parse(tokens[i++]); m.maxSpeed[3] = float.Parse(tokens[i++]); } MoveHorizontalUntilCollision mh = p.first.GetComponent <MoveHorizontalUntilCollision>(); if (mh != null) { mh.speed = float.Parse(tokens[i++]); } } }
private void Start() { activeState = PathFollowing; meshRenderer = GetComponentInChildren <SkinnedMeshRenderer>(); pathFollowing = GetComponent <PathFollowing>(); }
// Description: // Updates the UI position and displays the correct // menu for the input index in the grid. private void UpdatePlacementUI(Vector2 touchPosition, bool updatePosition = true) { // Update position if (updatePosition) { PlacementUI.transform.position = new Vector3(touchPosition.x, touchPosition.y, PlacementUI.transform.position.z); } bool foregroundObjectPresent = levelManager.isObjectAtPosition(touchPosition), backgroundObjectPresent = levelManager.isBackgroundObjectAtPosition(touchPosition); // Display correct menu if (!backgroundObjectPresent && !foregroundObjectPresent) { PlacementUI.transform.Find("ReplaceRemove").gameObject.SetActive(false); PlacementUI.transform.Find("ReplaceRemove/PathBtn").gameObject.SetActive(false); } else { PlacementUI.transform.Find("ReplaceRemove").gameObject.SetActive(true); PlacementUI.transform.Find("ReplaceRemove/PathBtn").gameObject.SetActive(false); bool showReplaceButton = activeKey != "" && (database[activeKey].first.tag != "PaintableBackground" && foregroundObjectPresent || database[activeKey].first.tag == "PaintableBackground" && backgroundObjectPresent); PlacementUI.transform.Find("ReplaceRemove/ReplaceBtn").gameObject.SetActive(showReplaceButton); pathSliderGroup.SetActive(false); jumpSliderGroup.SetActive(false); moveSliderGroup.SetActive(false); aiHorizMoveSliderGroup.SetActive(false); Pair <GameObject, GameObject> selectedObject; if (foregroundObjectPresent) { selectedObject = levelManager.getObjectAtPosition(touchPosition); } else { selectedObject = levelManager.getBackgroundObjectAtPosition(touchPosition); } PathFollowing p = selectedObject.second.GetComponent <PathFollowing>(); if (p != null) { p.startDrawingPath(); } p = selectedObject.first.GetComponent <PathFollowing>(); if (p != null) { PlacementUI.transform.Find("ReplaceRemove/PathBtn").gameObject.SetActive(true); if (!p.isEmpty()) { pathSliderGroup.SetActive(true); } if (p.currentState == PathFollowing.PathState.Idle) { p.setStateToPlaying(); lastObjectSelected = selectedObject; // Set slider tab to correct position float xpos = (((p.pathSpeed - 1f) / 8f) * 5.6f) - 2.8f; pathSliderTab.transform.localPosition = new Vector3(xpos, pathSliderTab.transform.localPosition.y, 0f); } } Jump j = selectedObject.first.GetComponent <Jump>(); if (j != null) { jumpSliderGroup.SetActive(true); float xpos = (((j.burst - 2f) / 8f) * 5.6f) - 2.8f; jumpSliderTab.transform.localPosition = new Vector3(xpos, jumpSliderTab.transform.localPosition.y, 0f); } Move m = selectedObject.first.GetComponent <Move>(); if (m != null) { moveSliderGroup.SetActive(true); float speed = 0f; for (int i = 0; i < 4; i++) { if (!Mathf.Approximately(m.maxSpeed[i], 0f)) { speed = m.maxSpeed[i]; break; } } if (!Mathf.Approximately(speed, 0f)) { float xpos = (((speed - 2f) / 8f) * 5.6f) - 2.8f; moveSliderTab.transform.localPosition = new Vector3(xpos, moveSliderTab.transform.localPosition.y, 0f); } } MoveHorizontalUntilCollision mh = selectedObject.first.GetComponent <MoveHorizontalUntilCollision>(); if (mh != null) { aiHorizMoveSliderGroup.SetActive(true); if (!Mathf.Approximately(mh.speed, 0f)) { float xpos = ((mh.speed / 8f) * 5.6f) - 2.8f; aiHorizMoveSliderTab.transform.localPosition = new Vector3(xpos, aiHorizMoveSliderTab.transform.localPosition.y, 0f); } } } }
// Use this for initialization void Start() { pathFollowing = GetComponent <PathFollowing>(); }
private void buttonPressedHandler(object sender, EventArgs e) { if (levelManager.loading) { return; } PressGesture gesture = (PressGesture)sender; GameObject s = gesture.gameObject; if (s.name.Equals(pathBtn.name)) { // Get GameObject at touch location and add a PathFollowing component to it Pair <GameObject, GameObject> selectedObject = levelManager.getObjectAtPosition(Camera.main.ScreenToWorldPoint(touchManager.ActiveTouches[0].Position)); if (selectedObject != null) { PathFollowing p = selectedObject.second.GetComponent <PathFollowing>(); if (p != null) { DestroyImmediate(p); p = null; p = selectedObject.first.GetComponent <PathFollowing>(); DestroyImmediate(p); } selectedObject.first.AddComponent <PathFollowing>().initDrawing(touchManager.ActiveTouches[touchManager.ActiveTouches.Count - 1].Id, true); selectedObject.second.AddComponent <PathFollowing>().initDrawing(touchManager.ActiveTouches[touchManager.ActiveTouches.Count - 1].Id, false); } } else if (s.name.Equals(replaceBtn.name)) { ReplaceObject(); } else if (s.name.Equals(removeBtn.name)) { RemoveObject(false); } else if (s.name.Equals(pathSliderTab.name)) { pathSliderTouchID = touchManager.ActiveTouches[touchManager.ActiveTouches.Count - 1].Id; } else if (s.name.Equals(jumpSliderTab.name)) { jumpSliderTouchID = touchManager.ActiveTouches[touchManager.ActiveTouches.Count - 1].Id; } else if (s.name.Equals(moveSliderTab.name)) { moveSliderTouchID = touchManager.ActiveTouches[touchManager.ActiveTouches.Count - 1].Id; } else if (s.name.Equals(aiHorizMoveSliderTab.name)) { aiHorizMoveSliderTouchID = touchManager.ActiveTouches[touchManager.ActiveTouches.Count - 1].Id; } else if (s.name.Equals(resetBtn.name)) { levelManager.revert(); levelManager.paused = true; Time.timeScale = 0; } else if (s.name.Equals(exitBtn.name)) { #if UNITY_EDITOR UnityEditor.EditorApplication.isPlaying = false; #else Application.Quit(); #endif } else if (s.name.Equals(cameraBtn.name)) { cameraOutline.SetActive(!cameraOutline.activeSelf); cameraPanel.SetActive(!cameraPanel.activeSelf); snapToGridBtn.GetComponent <Animator>().SetBool("Checked", snapToGrid); } else if (s.name.Equals(saveBtn.name)) { System.Windows.Forms.SaveFileDialog sfd = new System.Windows.Forms.SaveFileDialog(); sfd.Filter = "Level Design TIME Save File (*.lts)|*.lts"; sfd.FilterIndex = 0; if (sfd.ShowDialog() == System.Windows.Forms.DialogResult.OK) { saveLoad.save(sfd.FileName); } } else if (s.name.Equals(loadBtn.name)) { levelManager.paused = true; Time.timeScale = 0; System.Windows.Forms.OpenFileDialog ofd = new System.Windows.Forms.OpenFileDialog(); ofd.Filter = "Level Design TIME Save File (*.lts)|*.lts"; ofd.FilterIndex = 0; if (ofd.ShowDialog() == System.Windows.Forms.DialogResult.OK) { levelManager.loading = true; loadingSign.SetActive(true); StartCoroutine(saveLoad.loadGame(ofd.FileName)); } } else if (s.name.Equals(snapToGridBtn.name)) { snapToGrid = !snapToGrid; snapToGridBtn.GetComponent <Animator>().SetBool("Checked", snapToGrid); } else if (s.name.Equals(bottomCamCanvas.name)) { Vector2 touchPosition = Camera.main.ScreenToWorldPoint(touchManager.ActiveTouches[0].Position); PlacementUI.SetActive(true); if (activeKey != "" && (database[activeKey].first.tag == "PaintableBackground" || !levelManager.isObjectAtPosition(touchPosition))) { database[activeKey].first.SetActive(true); database[activeKey].second.SetActive(true); } if (activeKey != "" && database[activeKey].first.tag == "PaintableBackground") { if (database[activeKey].first.GetComponent <SpriteRenderer>() != null) { PlaceObject(touchPosition, true); } else { RemoveObject(true); } dragging = true; dragStartPosition = touchPosition; } else if (levelManager.isObjectAtPosition(touchPosition)) { dragging = true; dragStartPosition = touchPosition; } } }
private void handleSliderTouches(Vector2 touchPosition) { if (pathSliderTouchID > -1) { bool found = false; for (int i = 0; i < touchManager.ActiveTouches.Count; i++) { if (touchManager.ActiveTouches[i].Id == pathSliderTouchID) { found = true; float xpos = Camera.main.ScreenToWorldPoint(touchManager.ActiveTouches[i].Position).x; xpos = Mathf.Max(Mathf.Min(xpos, pathSliderGroup.transform.position.x + SLIDER_MAX_X), pathSliderGroup.transform.position.x + SLIDER_MIN_X); pathSliderTab.transform.position = new Vector3(xpos, pathSliderTab.transform.position.y, pathSliderTab.transform.position.z); float newPathSpeed = ((pathSliderTab.transform.localPosition.x + 2.8f) / 5.6f) * 8f + 1f; Pair <GameObject, GameObject> selectedObject = levelManager.getObjectAtPosition(touchPosition); if (selectedObject != null) { PathFollowing p = selectedObject.first.GetComponent <PathFollowing>(); if (p != null) { p.pathSpeed = newPathSpeed; } } break; } } if (!found) { pathSliderTouchID = -1; } } if (jumpSliderTouchID > -1) { bool found = false; for (int i = 0; i < touchManager.ActiveTouches.Count; i++) { if (touchManager.ActiveTouches[i].Id == jumpSliderTouchID) { found = true; float ypos = Camera.main.ScreenToWorldPoint(touchManager.ActiveTouches[i].Position).y; ypos = Mathf.Max(Mathf.Min(ypos, jumpSliderGroup.transform.position.y + SLIDER_MAX_X), jumpSliderGroup.transform.position.y + SLIDER_MIN_X); jumpSliderTab.transform.position = new Vector3(jumpSliderTab.transform.position.x, ypos, jumpSliderTab.transform.position.z); float newJumpBurst = ((jumpSliderTab.transform.localPosition.x + 2.8f) / 5.6f) * 8f + 2f; Pair <GameObject, GameObject> selectedObject = levelManager.getObjectAtPosition(touchPosition); if (selectedObject != null) { Jump j = selectedObject.first.GetComponent <Jump>(); if (j != null) { j.burst = newJumpBurst; } } break; } } if (!found) { jumpSliderTouchID = -1; } } if (moveSliderTouchID > -1) { bool found = false; for (int i = 0; i < touchManager.ActiveTouches.Count; i++) { if (touchManager.ActiveTouches[i].Id == moveSliderTouchID) { found = true; float xpos = Camera.main.ScreenToWorldPoint(touchManager.ActiveTouches[i].Position).x; xpos = Mathf.Max(Mathf.Min(xpos, moveSliderGroup.transform.position.x + SLIDER_MAX_X), moveSliderGroup.transform.position.x + SLIDER_MIN_X); moveSliderTab.transform.position = new Vector3(xpos, moveSliderTab.transform.position.y, moveSliderTab.transform.position.z); float newMoveSpeed = ((moveSliderTab.transform.localPosition.x + 2.8f) / 5.6f) * 8f + 2f; Pair <GameObject, GameObject> selectedObject = levelManager.getObjectAtPosition(touchPosition); if (selectedObject != null) { Move m = selectedObject.first.GetComponent <Move>(); if (m != null) { m.setMaxSpeed(newMoveSpeed); } } break; } } if (!found) { moveSliderTouchID = -1; } } if (aiHorizMoveSliderTouchID > -1) { bool found = false; for (int i = 0; i < touchManager.ActiveTouches.Count; i++) { if (touchManager.ActiveTouches[i].Id == aiHorizMoveSliderTouchID) { found = true; float xpos = Camera.main.ScreenToWorldPoint(touchManager.ActiveTouches[i].Position).x; xpos = Mathf.Max(Mathf.Min(xpos, aiHorizMoveSliderGroup.transform.position.x + SLIDER_MAX_X), aiHorizMoveSliderGroup.transform.position.x + SLIDER_MIN_X); aiHorizMoveSliderTab.transform.position = new Vector3(xpos, aiHorizMoveSliderTab.transform.position.y, aiHorizMoveSliderTab.transform.position.z); float newMoveSpeed = ((aiHorizMoveSliderTab.transform.localPosition.x + 2.8f) / 5.6f) * 8f; Pair <GameObject, GameObject> selectedObject = levelManager.getObjectAtPosition(touchPosition); if (selectedObject != null) { MoveHorizontalUntilCollision mh = selectedObject.first.GetComponent <MoveHorizontalUntilCollision>(); if (mh != null) { mh.speed = newMoveSpeed; } } break; } } if (!found) { moveSliderTouchID = -1; } } }
public void AttackRadius(Vector3 center, float radius) { //for (int i = 0; i < m_EnemyManager.m_EnemyDistance.Count; i++) //{ // float distance = Vector3.Distance(center, m_EnemyManager.m_EnemyPathFollowing[i].transform.position); // if (distance <= radius && !m_PathFollow.Contains(m_EnemyManager.m_EnemyPathFollowing[i])) // { // m_PathFollow.Add(m_EnemyManager.m_EnemyPathFollowing[i]); // m_Distances[i] = m_EnemyManager.m_EnemyDistance[i]; // } // else if (distance > radius && m_PathFollow.Contains(m_EnemyManager.m_EnemyPathFollowing[i])) // { // m_PathFollow.Remove(m_EnemyManager.m_EnemyPathFollowing[i]); // m_Distances[i] = m_EnemyManager.m_EnemyDistance[i]; // } //} // //foreach (float enemy in m_Distances) //{ // //} // //if (m_PathFollow.Count != 0) //{ // int _indexOf = m_Distances.IndexOf(m_Distances.Min()); // for (int y = 0; y < ObjectToTurn.Length; y++) // ObjectToTurn[y].LookAt(m_PathFollow[_indexOf].transform.position); // Fire(); //} //else // StopFiring(); //for (int i = 0; i < m_EnemyManager.m_EnemyPathFollowing.Count; i++) //{ // if (m_EnemyManager.m_EnemyPathFollowing[i].isActiveAndEnabled) // { // float distance = Vector3.Distance(center, m_EnemyManager.m_EnemyPathFollowing[i].transform.position); // if (distance < radius) // { // m_PathFollow.Add(m_EnemyManager.m_EnemyPathFollowing[i]); // } // else if (m_PathFollow.Contains(m_EnemyManager.m_EnemyPathFollowing[i])) // { // m_PathFollow.Remove(m_EnemyManager.m_EnemyPathFollowing[i]); // } // } //} Collider[] hitCollider = (Physics.OverlapSphere(transform.position, radius, 1 << 10)); if (hitCollider.Length != 0) { for (int i = 0; i < hitCollider.Length; i++) { if (hitCollider[i].gameObject.activeSelf) { //get the highest waypoint //pathFollow[x] = \ //PathFollowing _currentWayPoint = hitCollider[i].gameObject.GetComponent<PathFollowing>(); PathFollowing _currentWayPoint = hitCollider[i].gameObject.GetComponent <PathFollowing>(); m__currentObject = _currentWayPoint.gameObject; if (_currentWayPoint.m_EntireDistance < m_LowestDistance) { m_LowestDistance = _currentWayPoint.m_EntireDistance; _currentObject = _currentWayPoint.gameObject; } //if (_currentWayPoint.currentWayPoint <= Mathf.Max(m_WayPoints.ToArray())) //{ //int _indexOf = m_Distances.IndexOf(m_Distances.Min()); // = m_Distances.IndexOf(Mathf.Min(m_Distances.ToArray())); //int highest = Mathf.Max(pathFollow[x].currentWayPoint); //float highestDistance = Mathf.Min(pathFollow[x].distance); for (int y = 0; y < ObjectToTurn.Length; y++) { ObjectToTurn[y].LookAt(_currentObject.transform.position); } Fire(); //if (!m_Distances.Contains(_currentWayPoint.m_EntireDistance) && !m_PathFollow.Contains(_currentWayPoint)) //{ // m_Distances.Add(_currentWayPoint.m_EntireDistance); // m_PathFollow.Add(_currentWayPoint); //} // //for (int s = 0; s < m_PathFollow.Count; s++) //{ // float distance = Vector3.Distance(center, _currentWayPoint.transform.position); // if (!_currentWayPoint.gameObject.activeInHierarchy || distance > radius) // { // m_Distances.Remove(_currentWayPoint.m_EntireDistance); // m_PathFollow.Remove(_currentWayPoint); // } //} //} //else if (_currentWayPoint.currentWayPoint > Mathf.Max(m_WayPoints.ToArray())) //{ // m_WayPoints.Clear(); // m_WayPoints.Add(_currentWayPoint.currentWayPoint); // m_PathFollow.Add(_currentWayPoint); //} //int currentEnemy = x; //for (int y = 0; y < hitCollider.Length; y++) //{ // float highest2 = Mathf.Min(pathFollow[y].distance); // int currentEnemy = y; // ObjectToTurn.LookAt(hitCollider[x].transform.position); // Fire(); //} } } } else { StopFiring(); } }