public VillagerController ClosestEnemyVillager(List <VillagerController> _VillagerToFind, GameObject AgressiveVillager) { float ClosestDistance = 50; VillagerController _ClosestVillager = null; foreach (VillagerController _Villager in _VillagerToFind) { if (_Villager != null) { if (_Villager.GetComponent <TeamSide>()._team != AgressiveVillager.GetComponent <TeamSide>()._team&& _Villager.gameObject != AgressiveVillager) { float Distance = Vector3.Distance(AgressiveVillager.transform.position, _Villager.transform.position); if (Distance < ClosestDistance) { ClosestDistance = Distance; _ClosestVillager = _Villager; } } else { continue; } } } return(_ClosestVillager); }
public void SetOwner(VillagerController villagerController) { if (VillagerController != null) { return; } VillagerController = villagerController; }
void OnTriggerExit2D(Collider2D col) { if (col.gameObject.tag == "Villager") { touchingVillager = false; villager = null; } }
// Start is called before the first frame update void Start() { pb = GameObject.Find("Player").GetComponent <PlayerBehaviors>(); if (sideQuestObj) { villager = GameObject.Find(villagerName).GetComponent <VillagerController>(); score = GameObject.Find("Score").GetComponent <ScoreManager>(); } }
void OnTriggerEnter2D(Collider2D col) { if (col.gameObject.tag == "Villager") { pb.villagerTouchName = col.gameObject.name; touchingVillager = true; villager = col.gameObject.GetComponent <VillagerController>(); } }
private void Awake() { _villagerModel = GetComponent <VillagerModel>(); _villagerNeeds = GetComponent <VillagerNeedsController>(); _villagerView = GetComponent <VillagerView>(); _villagerController = GetComponent <VillagerController>(); _townController = TownController.Instance; _spawnController = SpawnController.Instance; }
public Villager createVillager(Building home, Vector2 pos) { Villager data = new Villager(home); GameObject go = Instantiate(villager); go.transform.position = pos; go.transform.SetParent(this.transform); VillagerController vc = go.AddComponent <VillagerController> (); vc.AddVillagerData(data); vc.AddHomeTile(pos); AvailableVillagersData.Add(data); VillagerGameObjcts.Add(data, go); return(data); }
void Start () { controller = FindObjectOfType<VillagerController> (); controller.OnGameOver += OnGameOver; controller.OnStartGame += OnStartGame; }
// Update is called once per frame void Update () { if(isHoldingVillager && holdLocation.childCount == 0 ){ heldVillager = null; heldVillagerRigid = null; heldVillagerScript = null; } //checkJoystickInput(); /* if(Input.GetKeyDown(KeyCode.Space)){ this.gameObject.SetActive(false); } */ checkDirection(); if(xMov != 0 || yMov != 0){ isWalking = true; }else{ isWalking = false; } anim.SetBool("isHolding", isHoldingVillager); anim.SetBool("isWalking", isWalking); xMov = 0f; yMov = 0f; xTemp = 0f; yTemp = 0f; if(!isDizzy){ if(isPlayerOne){ xTemp = Input.GetAxis("P1_Horizontal"); yTemp = Input.GetAxis("P1_Vertical"); }else{ xTemp = Input.GetAxis("P2_Horizontal"); yTemp = Input.GetAxis("P2_Vertical"); } }else{ if(isPlayerOne){ xTemp = Input.GetAxis("P1_Horizontal") * randomDirection; yTemp = Input.GetAxis("P1_Vertical") * randomDirection; }else{ xTemp = Input.GetAxis("P2_Horizontal") * randomDirection; yTemp = Input.GetAxis("P2_Vertical") * randomDirection; } } if(xTemp > .5 || xTemp < .5){ xMov = xTemp; }else{ xMov = 0; } if(yMov > .5 || yMov < .5){ yMov = yTemp ; }else{ yMov = 0; } rb.velocity = new Vector3(xMov, 0, -yMov).normalized * Time.deltaTime * moveSpeed; //Debug.Log(rb.velocity); if(isHoldingVillager && canAction){ if(isPlayerOne){ if(Input.GetButtonDown("P1_Pickup")){ throwVillager(new Vector3(rb.velocity.x, throwUpSpeed, rb.velocity.z)); } } else{ if(Input.GetButtonDown("P2_Pickup")){ throwVillager(new Vector3(rb.velocity.x, throwUpSpeed, rb.velocity.z)); } } } }
private void throwVillager(Vector3 throwAngle){ anim.Play("Chief_Throw"); isHoldingVillager = false; heldVillagerRigid.isKinematic = false; heldVillager.transform.parent = null; heldVillagerRigid.velocity = throwAngle * reducedThrowSpeed; heldVillagerScript.thrown(); //heldVillagerScript.setHoldState(isHoldingVillager); heldVillager = null; heldVillagerRigid = null; heldVillagerScript = null; //Debug.Log(throwAngle); //Debug.Log(heldVillagerRigid.velocity); startCooldown(); }
void OnTriggerStay(Collider other){ if(other.tag == "Villager" && isHoldingVillager == false && canAction){ if(isPlayerOne){ if(Input.GetButtonDown("P1_Pickup")){ isHoldingVillager = true; //Set held villager components for later use heldVillager = other.gameObject; heldVillagerScript = heldVillager.GetComponent<VillagerController>(); heldVillagerRigid = heldVillager.GetComponent<Rigidbody>(); //Put villager above player and disable his movement heldVillager.transform.position = holdLocation.position; heldVillager.transform.parent = holdLocation; heldVillagerRigid.isKinematic = true; heldVillagerScript.setHoldState(isHoldingVillager); canAction = false; startCooldown(); } }else{ if(Input.GetButtonDown("P2_Pickup")){ isHoldingVillager = true; //Set held villager components for later use heldVillager = other.gameObject; heldVillagerScript = heldVillager.GetComponent<VillagerController>(); heldVillagerRigid = heldVillager.GetComponent<Rigidbody>(); //Put villager above player and disable his movement heldVillager.transform.position = holdLocation.position; heldVillager.transform.parent = holdLocation; heldVillagerRigid.isKinematic = true; heldVillagerScript.setHoldState(isHoldingVillager); canAction = false; startCooldown(); } } } }
// Update is called once per frame void Update() { //LeftMouseButton takes array of targets(villagers) with rightclick move on position //if (Input.GetMouseButtonDown(0)) if (agent.remainingDistance <= distanceLeft) { //Debug.Log("Remaining Distance"); agent.isStopped = true; } if (isSelected == true) { if (Input.GetMouseButtonDown(1)) { Ray ray = cam.ScreenPointToRay(Input.mousePosition); RaycastHit hit; if (Physics.Raycast(ray, out hit)) { resourceManager = hit.collider.gameObject.GetComponent <RessourcesManager>(); if (resourceManager != null) { Debug.Log("HOER resssssour" + resourceManager.resourceType); } MoveToPoint(hit.point); isSelected = false; Debug.Log("We hit: " + hit.collider.name + " " + hit.point); //Move target to what we hit } } } if (inventory >= maxInventory) { MoveToPoint(GameObject.Find("TownCenters").transform.GetChild(0).gameObject.GetComponent <TownCenterController>().storagePlace.transform.position); inventoryIsFull = true; } else { inventoryIsFull = false; } if (resourceManager != null) { //Task State Machine //at TownCenter if (!inventoryIsFull) { if (agent.isStopped == true && !isBringingBack) { Debug.Log("HOER HJ"); Invoke("GatherRessources", gatherWaitSeconds); isGathering = true; } } //at TownCenter else { if (agent.isStopped == true && !isGathering) { BringBackRessources(); inventory = 0; isBringingBack = true; } } } #region UnitSelection // If we press the left mouse button, begin selection and remember the location of the mouse if (Input.GetMouseButtonDown(0)) { isSelecting = true; mousePosition1 = Input.mousePosition; //check if List is empty , otherwise empty it foreach (var selectableObject in FindObjectsOfType <SelectableUnitComponents>()) { if (selectableObject.selectionCircle != null) { Destroy(selectableObject.selectionCircle.gameObject); selectableObject.selectionCircle = null; } } } // If we let go of the left mouse button, end selection if (Input.GetMouseButtonUp(0)) { //create a new List "selectedObjects" and add "selectableObjects" within 'selection bounds' var selectedObjects = new List <SelectableUnitComponents>(); foreach (var selectableObject in FindObjectsOfType <SelectableUnitComponents>()) { if (IsWithinSelectionBounds(selectableObject.gameObject)) { selectedObjects.Add(selectableObject); Debug.Log("Selected Objects Count: " + selectedObjects.Count); //activate movement on selectedThings //überrest aus mech?! VillagerController villagerController = selectableObject.GetComponent <VillagerController>(); if (villagerController != null) { villagerController.isSelected = true; } } } //string builder [nochmal anschauen] var sb = new StringBuilder(); sb.AppendLine(string.Format("Selecting [{0}] Units", selectedObjects.Count)); foreach (var selectedObject in selectedObjects) { sb.AppendLine("-> " + selectedObject.gameObject.name); } Debug.Log(sb.ToString()); isSelecting = false; } // Highlight all objects within the selection box //buggy :b if (isSelecting) { foreach (var selectableObject in FindObjectsOfType <SelectableUnitComponents>()) { if (IsWithinSelectionBounds(selectableObject.gameObject)) { if (selectableObject.selectionCircle == null) { selectableObject.selectionCircle = Instantiate(selectionCirclePrefab); selectableObject.selectionCircle.transform.SetParent(selectableObject.transform, false); selectableObject.selectionCircle.transform.eulerAngles = new Vector3(90, 0, 0); } } else { if (selectableObject.selectionCircle != null) { Destroy(selectableObject.selectionCircle.gameObject); selectableObject.selectionCircle = null; } } } } }
void Start() { vm = gameObject.GetComponent <VillagerController>(); anim = gameObject.GetComponent <Animator>(); }
private void Awake() { _villagerModel = GetComponent <VillagerModel>(); _villagerController = GetComponent <VillagerController>(); }
void Update() { // If we press the left mouse button, begin selection and remember the location of the mouse if (Input.GetMouseButtonDown(0)) { isSelecting = true; mousePosition1 = Input.mousePosition; foreach (var selectableObject in FindObjectsOfType <SelectableUnitComponents>()) { if (selectableObject.selectionCircle != null) { Destroy(selectableObject.selectionCircle.gameObject); selectableObject.selectionCircle = null; } } } // If we let go of the left mouse button, end selection if (Input.GetMouseButtonUp(0)) { var selectedObjects = new List <SelectableUnitComponents>(); foreach (var selectableObject in FindObjectsOfType <SelectableUnitComponents>()) { if (IsWithinSelectionBounds(selectableObject.gameObject)) { selectedObjects.Add(selectableObject); Debug.Log("Selected Objects Count: " + selectedObjects.Count); VillagerController villagerController = selectableObject.GetComponent <VillagerController>(); if (villagerController != null) { villagerController.isSelected = true; } } } var sb = new StringBuilder(); sb.AppendLine(string.Format("Selecting [{0}] Units", selectedObjects.Count)); foreach (var selectedObject in selectedObjects) { sb.AppendLine("-> " + selectedObject.gameObject.name); } Debug.Log(sb.ToString()); isSelecting = false; } // Highlight all objects within the selection box if (isSelecting) { foreach (var selectableObject in FindObjectsOfType <SelectableUnitComponents>()) { if (IsWithinSelectionBounds(selectableObject.gameObject)) { if (selectableObject.selectionCircle == null) { selectableObject.selectionCircle = Instantiate(selectionCirclePrefab); selectableObject.selectionCircle.transform.SetParent(selectableObject.transform, false); selectableObject.selectionCircle.transform.eulerAngles = new Vector3(90, 0, 0); } } else { if (selectableObject.selectionCircle != null) { Destroy(selectableObject.selectionCircle.gameObject); selectableObject.selectionCircle = null; } } } } }
public void OnGatherResource() { if (_ObjOfFocus != null) { if (_Task == VillagerTask.Combat) { if (_ObjOfFocus.GetComponent <VillagerController>()) //Makes the other villager attack this villager back { VillagerController Villager = _ObjOfFocus.GetComponent <VillagerController>(); if (Villager._ObjOfFocus != null) { if (Villager._ObjOfFocus.GetComponent <WorldResource>() != null) { Villager._ObjOfFocus.GetComponent <WorldResource>()._SupplyBeingTaken = false; } } Villager._Wood = 0; Villager._Stone = 0; Villager._Food = 0; Villager._Task = VillagerTask.Combat; Villager._ObjOfFocus = this.gameObject; Villager._WantedGoal = ResourceType.combat; } if (_ObjOfFocus.GetComponent <ITakeDamage>() != null && _ObjOfFocus.GetComponent <WorldResource>() == null) { _ObjOfFocus.GetComponent <ITakeDamage>().TakeDamage(20); //Deal damage to other entity } else { Destroy(_CurrentTool); _Task = VillagerTask.GatherResources; } } else { if (_ObjOfFocus.GetComponent <ITakeDamage>() != null) { _ObjOfFocus.GetComponent <ITakeDamage>().TakeDamage(1); //Deal damage to resources } } if (_CurrentTool != null) { if (_CurrentTool.GetComponentInChildren <ParticleSystem>() != null) { _CurrentTool.GetComponentInChildren <ParticleSystem>().Play(); } } if (_Task == VillagerTask.GatherResources) //Gather resources { switch (_WantedGoal) { case ResourceType.wood: _Wood += 1; _Audio.pitch = Random.Range(0.8f, 1.2f); PlaySound(_WoodHit); break; case ResourceType.stone: _Stone += 1; _Audio.pitch = Random.Range(0.8f, 1.2f); PlaySound(_StoneHit); break; case ResourceType.food: _Food += 1; _Audio.pitch = Random.Range(0.8f, 1.2f); PlaySound(_WoodHit); break; } } } }