private void NearestTree() { //Nearest tree distance variable. float nearest = 1000000000f; TreeScript treeScript = null; //Check in list the nearest tree foreach (GameObject tree in treeList) { //Check if the object in list is not null if (tree != null) { //Distance variable between AI and tree. float distance = Vector3.Distance(tree.transform.position, this.transform.position); //Check if Distance from the apple is lesser than the previous apple if (distance < nearest) { nearest = distance; treeGameObj = tree; treeScript = tree.GetComponent <TreeScript>(); } movingToTree = true; } } //if the script is not null the variable chosen tree became true, this will control the next behavior of the AI. if (treeScript != null) { treeScript.chosenTree = true; } }
//Inform if the AI get sight of a tree public bool TreeSight(GameObject tree) { //Get the cosene of the angle between the foward vector from AI and the vector from the tree float cosAngle = Vector3.Dot((tree.transform.position - this.transform.position).normalized, this.transform.forward); //transform the angle from radians to degrees float angle = Mathf.Acos(cosAngle) * Mathf.Rad2Deg; //Distance between AI and tree. float distance = Vector3.Distance(this.transform.position, tree.transform.position); //Get Handler to TreeScript. TreeScript treeScript = tree.GetComponent <TreeScript>(); //If the angle is minor than the cutoff (45 degres) and the distance is minor than 50.0f then the AI is seeing the tree. if (angle < cutoff && distance < 100.0f) { //Change variable to stop GameObject to continue going on list. if (treeScript.inList == false) { treeScript.inList = true; //Insert tree on the list. InsertTreeInList(tree); } //Draw a line from the player to the apple. Debug.DrawLine(transform.position, tree.transform.position, Color.green); //return true. return(true); } //return false. return(false); }
private void Update() { isDriving = sm.isDriving; if (isDriving) { isEquiped = false; axe.SetActive(false); } else { if (!axe.activeSelf && Input.GetKeyDown(KeyCode.Alpha0)) { isEquiped = true; axe.SetActive(true); } else if (Input.GetKeyDown(KeyCode.Alpha0)) { isEquiped = false; axe.SetActive(false); } //Raycast Vector3 fwd = transform.TransformDirection(Vector3.forward); RaycastHit hit; if (Physics.Raycast(transform.position, fwd, out hit, rayCastLength)) { if (hit.collider.tag == "tree" && Input.GetButtonDown("Crop") && isEquiped == true) { TreeScript treeScript = hit.collider.gameObject.GetComponent <TreeScript>(); treeScript.treeHealth--; } } } }
public bool CalculateAvailableNearestTree(Villager inVillager, out TreeScript nearestTree) { if (!AreAvailableTreesInSanctuary()) { nearestTree = null; return(false); } foreach (var tree in TreesPriorityQueue) { var distance = (inVillager.transform.position - tree.transform.position).magnitude; TreesPriorityQueue.UpdatePriority(tree, distance); } var treesArray = TreesPriorityQueue.ToArray(); for (var i = 0; i < treesArray.Length; i++) { if (!treesArray[i].isOccupied) { nearestTree = treesArray[i]; return(true); } } inVillager.UpdateAIText("No Available Trees"); nearestTree = null; return(false); }
void FindTree() { currenTree = null; Grid grid = FindObjectOfType <Grid>(); Node HutNode = grid.NodeFromWorldPoint(transform.position); foreach (GameObject tree in GameObject.FindGameObjectsWithTag("Tree")) { Node treeNode = grid.NodeFromWorldPoint(tree.transform.position); if (treeNode.gridX <= HutNode.gridX + Radius && treeNode.gridX >= HutNode.gridX - Radius && treeNode.gridY <= HutNode.gridY + Radius && treeNode.gridY >= HutNode.gridY - Radius) { TreeScript ts = tree.GetComponent <TreeScript>(); ObjectOnGrid oog = tree.GetComponent <ObjectOnGrid>(); if (ts.available && oog.placed) { currenTree = tree; ts.available = false; return; } } } }
private void OnTriggerEnter2D(Collider2D collision) { if (collision.tag == "tree") { Debug.Log("tree in range"); tree = collision.GetComponent <TreeScript>(); } }
void Start() { System.Random r = new System.Random(); ulong seed = (ulong)((r.NextDouble() * 2.0 - 1.0) * long.MaxValue); GameObject t = Instantiate(tree); TreeScript ts = t.GetComponent <TreeScript>(); ts.seed = seed; AppleScript.trees.Add(new Vector2(t.transform.position.x, t.transform.position.z)); }
// Start is called before the first frame update void Start() { gameSpeed = 45; ts = FindObjectOfType <TreeScript>(); dayColor = new Color(128 / 255f, 128 / 255f, 128 / 255f); nightColor = new Color(0f, 37 / 255f, 1f); RenderSettings.skybox.SetColor("_TintColor", dayColor); gameTimer = 48600f; //Setting the time to 1 PM at start SwitchCharacter(0); }
public void DestroyTree(TreeScript tree) { RemoveTargetTree(tree); Destroy(tree.gameObject); if (TreesPriorityQueue.Count <= 1) { bShouldSpawnTrees = true; } }
private void RecheckLayer(TreeScript tree) { if (tree.transform.position.y < this.transform.parent.position.y) { parentSprite.sortingOrder = tree.TreeSprite.sortingOrder - 1; tree.FadeIn(); } else { parentSprite.sortingOrder = tree.TreeSprite.sortingOrder + 1; } }
private void SetRoot() { level = 0; TreeScript ts = gameObject.transform.parent.gameObject.GetComponent <TreeScript>(); if (ts == null) { return; } ts.SetRoot(gameObject); }
private void OnTriggerExit2D(Collider2D collision) { if (collision.tag == "tree") { Debug.Log("tree no longer in range"); if (tree != null) { tree.StopHitting(); } tree = null; } }
void CollectFruit(TreeScript tree) { for (int i = 0; i < tree.currentFruit.Count; i++) { IM.AddFruit(tree.currentFruit[i].GetComponent <FruitScript>().fruitType, WM.SelectedIsland.GetComponent <IslandScript>().islandID); Destroy(tree.currentFruit[i]); } tree.currentFruit.Clear(); targetObject = null; }
public bool RemoveTargetTree(TreeScript tree) { if (!AreAvailableTreesInSanctuary()) { return(false); } if (!TreesPriorityQueue.Contains(tree)) { Debug.Log($"{tree.gameObject}Tree is not in the list of trees"); return(false); } TreesPriorityQueue.Remove(tree); return(true); }
public void SaveTrees() { //Debug.Log("SAVING TREES"); string filePath = Application.persistentDataPath + fileName; //string filePath = fileName; Debug.Log(filePath); if (File.Exists(filePath)) { JsonTrees jsonTrees = new JsonTrees() { types = new string[TreesInWorld.Count], growTimers = new float[TreesInWorld.Count], timeToGrows = new float[TreesInWorld.Count], worldIds = new int[TreesInWorld.Count], potIds = new int[TreesInWorld.Count], potLvls = new int[TreesInWorld.Count] }; int i = 0; foreach (var tree in TreesInWorld) { TreeScript TS = tree.GetComponent <TreeScript>(); jsonTrees.types[i] = TS.treeType; jsonTrees.growTimers[i] = TS.growTimer; jsonTrees.timeToGrows[i] = TS.timeToGrow; jsonTrees.worldIds[i] = tree.transform.parent.GetComponentInParent <IslandScript>().islandID; jsonTrees.potIds[i] = tree.transform.GetComponentInParent <PlantPot>().potID; jsonTrees.potLvls[i] = tree.transform.GetComponentInParent <PlantPot>().potLevel; i++; } string dataAsJson = JsonUtility.ToJson(jsonTrees); File.WriteAllText(filePath, dataAsJson); //Debug.Log("saved trees"); } else { File.Create(filePath).Dispose(); SaveTrees(); } }
public void OnTriggerEnter(Collider c) //germinate { if (c.tag == "Ground") { Vector2 spawnPoint = new Vector2(transform.position.x, transform.position.z); if (safeArea(spawnPoint)) { GameObject t = Instantiate(tree); t.transform.position = transform.position; TreeScript ts = t.GetComponent <TreeScript>(); ts.seed = seed; trees.Add(new Vector2(t.transform.position.x, t.transform.position.z)); Destroy(gameObject); } } }
// Use this for initialization protected virtual void Start() { treeScript = treeObject.GetComponent <TreeScript>(); newNameMap = new Dictionary <string, object>(); Users.Clear(); FirebaseApp.CheckAndFixDependenciesAsync().ContinueWith(task => { dependencyStatus = task.Result; if (dependencyStatus == DependencyStatus.Available) { InitializeFirebase(); } else { Debug.LogError( "Could not resolve all Firebase dependencies: " + dependencyStatus); } }); }
void Awake() { //Initalises variables if (GameObject.Find("Player") != null) { PlayerOB = GameObject.Find("PlayerGameObject"); } ShopScript = ShopTreeOB.GetComponent <TreeScript>(); GreenScript = GreenTreeOB.GetComponent <TreeScript>(); BlueScript = BlueTreeOB.GetComponent <TreeScript>(); BossScript = BossTreeOB.GetComponent <TreeScript>(); ShopPaths = GameObject.Find("ShopPaths"); BluePaths = GameObject.Find("BluePaths"); GreenPaths = GameObject.Find("GreenPaths"); shopButton = GameObject.Find("ShopPaths").GetComponent <Button>(); greenButton = GameObject.Find("GreenPaths").GetComponent <Button>(); blueButton = GameObject.Find("BluePaths").GetComponent <Button>(); }
void LoadTrees() { //Debug.Log("LOADING TREES"); string filePath = Application.persistentDataPath + fileName; //string filePath = fileName; if (File.Exists(filePath)) { string dataAsJson = File.ReadAllText(filePath); JsonTrees jsonTrees = JsonUtility.FromJson <JsonTrees>(dataAsJson); //Debug.Log(jsonTrees.types[0]); for (int i = 0; i < jsonTrees.types.Length; i++) { GameObject newTree = Instantiate( FindTree(jsonTrees.types[i]), WorldManager.Instance.islands[jsonTrees.worldIds[i]].GetComponent <IslandScript>().plantPots[jsonTrees.potIds[i]].transform.position, Quaternion.identity, WorldManager.Instance.islands[jsonTrees.worldIds[i]].GetComponent <IslandScript>().plantPots[jsonTrees.potIds[i]].transform ); TreesInWorld.Add(newTree); WorldManager.Instance.islands[jsonTrees.worldIds[i]].GetComponent <IslandScript>().currentTreePopulation++; TreeScript TS = newTree.GetComponent <TreeScript>(); TS.growTimer = jsonTrees.growTimers[i]; TS.timeToGrow = jsonTrees.timeToGrows[i]; TS.GetComponentInParent <PlantPot>().treeInPot = TS.gameObject; TS.GetComponentInParent <PlantPot>().potLevel = jsonTrees.potLvls[i]; TS.GetComponentInParent <PlantPot>().CheckSprite(); TS.loadedFromSave = true; } //Debug.Log("Loaded trees"); } else { SaveTrees(); } }
void FindNearestTree() { currenTree = null; float dist = float.MaxValue; Grid grid = FindObjectOfType <Grid>(); Node HutNode = grid.NodeFromWorldPoint(transform.position); foreach (GameObject tree in GameObject.FindGameObjectsWithTag("Tree")) { Node treeNode = grid.NodeFromWorldPoint(tree.transform.position); if (treeNode.gridX <= HutNode.gridX + Radius && treeNode.gridX >= HutNode.gridX - Radius && treeNode.gridY <= HutNode.gridY + Radius && treeNode.gridY >= HutNode.gridY - Radius) { TreeScript ts = tree.GetComponent <TreeScript>(); ObjectOnGrid oog = tree.GetComponent <ObjectOnGrid>(); if (ts.available && oog.placed) { float currTreeDist = Mathf.Sqrt(Mathf.Pow(treeNode.gridX - HutNode.gridX, 2) + Mathf.Pow(treeNode.gridY - HutNode.gridY, 2)); if (currTreeDist < dist) { currenTree = tree; dist = currTreeDist; } //ts.available = false; //return; } } } if (currenTree != null) { TreeScript ts = currenTree.GetComponent <TreeScript>(); ts.available = false; } }
//Move AI next to the tree. private void MoveToTree(GameObject treePosition) { TreeScript treeScript = treePosition.GetComponent <TreeScript>(); if (treePosition != null) { if (Vector3.Distance(treePosition.transform.position, transform.position) > 5.0f) { //Move the AI to the apple position. Vector3 positionToMove = new Vector3(treePosition.transform.position.x, this.transform.position.y, treePosition.transform.position.z); transform.position = Vector3.MoveTowards(this.transform.position, positionToMove, 5 * Time.deltaTime); } else { rotationLeft = 360; doingAction = false; movingToTree = false; madeRotation = false; debugger = true; } } }
// Use this for initialization void Start() { TreeScript = GameObject.Find("Tree").GetComponent <TreeScript>(); childs = new List <GameObject>(); }
void Update() { if (isDead) { Death(); } #region Health/Hunger/Stamina healthBar.fillAmount = health / maxHealth; hungerBar.fillAmount = hunger / maxHunger; staminaBar.fillAmount = stamina / maxStamina; if (health > maxHealth) { health = 10; } if (hunger == 0) { isDead = true; } #endregion #region Movement CharacterController controller = GetComponent <CharacterController>(); if (controller.isGrounded) { moveDirection = new Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical")); moveDirection = transform.TransformDirection(moveDirection); moveDirection *= speed; if (Input.GetButton("Jump")) { moveDirection.y = jumpSpeed; } if (Input.GetKey(KeyCode.LeftShift)) { speed = sprintSpeed; } if (Input.GetKeyUp(KeyCode.LeftShift)) { speed = 7.0f; } } #endregion if (Input.GetKeyDown(KeyCode.KeypadEnter)) { if (Cursor.lockState == CursorLockMode.None) { Cursor.lockState = CursorLockMode.Locked; } else if (Cursor.lockState == CursorLockMode.Locked) { Cursor.lockState = CursorLockMode.None; } } RaycastHit hit; float range = 4.5f; #region Controls //What to do when the player press the left mouse button. if (Input.GetMouseButtonDown(0)) { //If the player left clicks while having their mouse unlocked then lock their mouse if (Cursor.lockState == CursorLockMode.None) { Cursor.lockState = CursorLockMode.Locked; } //When The Player Presses Mouse 0 (Left Mouse Button) The Script Will Check If he hit something and if so what it hit. if (Physics.Raycast(cam.transform.position, cam.transform.forward, out hit, range)) { //If the player clicks on a tree... if (hit.transform.gameObject.tag == "Tree") { //Get the script for the tree that has just been hit TreeScript Target = hit.transform.GetComponent <TreeScript>(); //@@REMINDER@@ Replace attack number with Attack variable //Run the function that handles what to do when the tree is punched. Target.Punch(1); //Spawns a particle system wherever the player clicked. GameObject treeFX = Instantiate(timpactFX, hit.point, Quaternion.LookRotation(hit.normal)); //Then Destroys said particle system. Destroy(treeFX, 1f); } if (hit.transform.gameObject.tag == "Item") { ItemBehavior Target = hit.transform.gameObject.GetComponent <ItemBehavior>(); } } } #endregion //Movement Stuff moveDirection.y -= gravity * Time.deltaTime; controller.Move(moveDirection * Time.deltaTime); }
public WorldData(ControllerScript controller) { time = controller.time; ambientTemperature = controller.ambientTemperature; playerTemperature = controller.playerTemperature; currentSeason = controller.currentSeason; currentDay = controller.currentDay; currentDayInSeason = controller.currentDayInSeason; health = controller.playerInventoryScript.GetComponent <PlayerScript> ().health; hunger = controller.playerInventoryScript.GetComponent <PlayerScript> ().hunger; happiness = controller.playerInventoryScript.GetComponent <PlayerScript> ().happiness; droppedItems = new SaveSystem.MyDroppedItem[controller.GetComponent <SaveSystemScript>().items.Length]; terrains = new SaveSystem.MyTerrain[controller.GetComponent <SaveSystemScript> ().terrains.Length]; buildings = new SaveSystem.Buildings.BasicBuildingSaveProperties[controller.GetComponent <SaveSystemScript>().buildings.Length]; mobs = new SaveSystem.Mobs.BasicMobAttributes[controller.GetComponent <SaveSystemScript>().mobs.Length]; playerPosition = new MyVector3(controller.playerInventoryScript.transform.position); playerInventory = new SerializedInventoryItem[controller.playerInventoryScript.playerInventory.Length]; for (int i = 0; i < playerInventory.Length; i++) { playerInventory [i] = controller.playerInventoryScript.playerInventory [i].convertToSave(); } for (int i = 0; i < droppedItems.Length; i++) { if (controller.GetComponent <SaveSystemScript> ().items [i] != null) { droppedItems [i] = new SaveSystem.MyDroppedItem(controller.GetComponent <SaveSystemScript> ().items [i].transform.GetChild(0).GetComponent <DroppedItemScript> ().myValue.name, controller.GetComponent <SaveSystemScript> ().items [i].transform.GetChild(0).GetComponent <DroppedItemScript> ().myValue.quantity, new MyVector3(controller.GetComponent <SaveSystemScript> ().items [i].transform.position)); } } for (int i = 0; i < terrains.Length; i++) { if (controller.GetComponent <SaveSystemScript> ().terrains [i] != null) { GameObject terrain = controller.GetComponent <SaveSystemScript> ().terrains [i]; terrains [i] = new SaveSystem.MyTerrain(terrain.GetComponent <TerrainScript> ().terrainName, terrain.transform.position); } } for (int i = 0; i < mobs.Length; i++) { if (controller.GetComponent <SaveSystemScript> ().mobs [i] != null) { GameObject mob = controller.GetComponent <SaveSystemScript> ().mobs [i]; if (mob.GetComponent <PassiveFourLegs> () != null) { mobs [i] = new SaveSystem.Mobs.BasicMobAttributes(mob.GetComponent <PassiveFourLegs>().mobName, mob.GetComponent <PassiveFourLegs> ().health, mob.GetComponent <PassiveFourLegs> ().maxHealth, mob.transform.position, mob.transform.eulerAngles); } else if (mob.GetComponent <Sheep> () != null) { mobs [i] = new SaveSystem.Mobs.Sheep(mob.GetComponent <Sheep>().mobName, mob.GetComponent <Sheep> ().health, mob.GetComponent <Sheep> ().maxHealth, mob.transform.position, mob.transform.eulerAngles); } } } for (int i = 0; i < buildings.Length; i++) { if (controller.GetComponent <SaveSystemScript> ().buildings [i] != null) { GameObject building = controller.GetComponent <SaveSystemScript> ().buildings [i]; TreeScript treeScript = null; BoulderScript boulderScript = null; GrassScript grassScript = null; BushScript bushScript = null; BerryBushScript berryBushScript = null; FireScript fireScript = null; GroundFoodScript naturalFoodScript = null; if (building.GetComponent <TreeScript> () != null) { treeScript = building.GetComponent <TreeScript> (); } if (building.GetComponent <BoulderScript> () != null) { boulderScript = building.GetComponent <BoulderScript> (); } if (building.GetComponent <GrassScript> () != null) { grassScript = building.GetComponent <GrassScript> (); } if (building.GetComponent <BushScript> () != null) { bushScript = building.GetComponent <BushScript> (); } if (building.GetComponent <BerryBushScript> () != null) { berryBushScript = building.GetComponent <BerryBushScript> (); } if (building.GetComponent <FireScript> () != null) { fireScript = building.GetComponent <FireScript> (); } if (building.GetComponent <GroundFoodScript> () != null) { naturalFoodScript = building.GetComponent <GroundFoodScript> (); } if (treeScript != null || boulderScript != null) { //natural barriers if (treeScript != null) { buildings [i] = new SaveSystem.Buildings.NaturalBarriers("tree", treeScript.transform.position, treeScript.transform.eulerAngles, treeScript.health); } else if (boulderScript != null) { buildings [i] = new SaveSystem.Buildings.NaturalBarriers("boulder", boulderScript.transform.position, boulderScript.transform.eulerAngles, boulderScript.health); } } else if (grassScript != null || bushScript != null || berryBushScript != null) { if (grassScript != null) { buildings [i] = new SaveSystem.Buildings.NaturalCrops("grassPatch", grassScript.transform.position, grassScript.transform.eulerAngles, grassScript.cut, grassScript.growTimer); } if (bushScript != null) { buildings [i] = new SaveSystem.Buildings.NaturalCrops("bush", bushScript.transform.position, bushScript.transform.eulerAngles, bushScript.cut, bushScript.growTimer); } else if (berryBushScript != null) { buildings [i] = new SaveSystem.Buildings.NaturalCrops("berryBush", berryBushScript.transform.position, berryBushScript.transform.eulerAngles, berryBushScript.cut, berryBushScript.growTimer); } } else if (fireScript != null) { buildings [i] = new SaveSystem.Buildings.Campfire("campfire", fireScript.transform.position, fireScript.transform.eulerAngles, fireScript.fuel); } else if (naturalFoodScript != null) { buildings [i] = new SaveSystem.Buildings.BasicBuildingSaveProperties(naturalFoodScript.buildingIDName, naturalFoodScript.transform.position, naturalFoodScript.transform.eulerAngles); } } } }
public void CollidedWithTree(TreeScript tree) { Debug.Log("Hit by tree"); }
public void Attack() { if (Time.time >= attackCoolDown) { //Detect hittables in range Collider[] gotHit = Physics.OverlapSphere(attackPoint.position, attackRange, hittableLayers); //Apply damage to each hit object foreach (Collider hit in gotHit) { Resource hitResource = hit.GetComponent <Resource>(); TreeScript hitTree = hit.GetComponent <TreeScript>(); BuildingGhost buildingGhost = hit.GetComponent <BuildingGhost>(); Animal animal = hit.GetComponent <Animal>(); UseableItem item = hit.GetComponent <UseableItem>(); FarmPlot farmPlot = hit.GetComponent <FarmPlot>(); Plant plant = hit.GetComponent <Plant>(); //Getting resources if (hitResource) { hitResource.health -= attackDamage; audioManager.PlaySound("Hit Marker"); } //Tree chopping if (hitTree) { hitTree.ChopTree(attackDamage); audioManager.PlaySound("Hit Marker"); } //Building ghosts if (buildingGhost) { if (buildingGhost.requiredResource == "Wood") { if (GameController.Instance.resourceController.wood >= 1) { buildingGhost.AddResources(1); } } if (buildingGhost.requiredResource == "Stone") { if (GameController.Instance.resourceController.stone >= 1) { buildingGhost.AddResources(1); } } } //Hit animal if (animal) { animal.TakeDamage(attackDamage, this.transform); audioManager.PlaySound("Smack"); //Debug.Log("Dealt " + damage + " dmg to " + hit.transform.name); } //Pickup item if (item) { if (itemInHand == null) { item.pickedUp = true; itemInHand = hit.transform; audioManager.PlaySound("Item Pickup"); } } //Farming if (farmPlot) { farmPlot.PlantSeed(); } if (plant) { plant.Harvest(); } } attackCoolDown = Time.time + (1.0f / attackSpeed); } }
void OnTriggerStay(Collider other) { if (Input.GetMouseButtonDown (0)) { if(other.tag == "Tree") { if(inventory.getEquip()[0] == "Axe" || inventory.getEquip()[1] == "Axe") { audio.PlayOneShot(axeSound); tree = other.GetComponent<TreeScript>(); tree.treeHealth -= 1; } else { ui.showHinweis("Sie benötigen eine Axt um Bäume zu fällen", 3.0F); } } if(other.tag == "Cliff") { ui.showHinweis("Sie benötigen eine Picke um Steine zu schlagen", 3.0F); } } if(other.tag == "Wasser") { if(inventory.getBottles() > 0) { ui.showHinweis(true, "Mit 'E' kannst du Wasser trinken. Mit 'T' kannst du deine Flaschen auffüllen. "); if(Input.GetKeyDown(KeyCode.E)) { drink(0.2F); } if(Input.GetKeyDown(KeyCode.T)) inventory.addItemToInventory("FlascheWasser"); } else { ui.showHinweis(true, "Mit 'E' kannst du Wasser trinken."); if(Input.GetKeyDown(KeyCode.E)) { drink(0.2F); } } } if (other.tag == "Meer") { if (Input.GetMouseButtonDown (0)) { if(inventory.getEquip()[0] == "Net" || inventory.getEquip()[1] == "Net") { if((lastTimeFish - tod.Hour) <= -2) { int fishcatched = Random.Range(0,3) + 1; audio.PlayOneShot(fishingSound); ui.showHinweis("Du hast " + fishcatched + " Fische gefangen. Du kannst in 2 Stunden wieder fischen.", 2.0F); for(int i = 0; i < fishcatched; i++) { inventory.addItemToInventory("Fish"); }; lastTimeFish = tod.Hour; } else if((lastTimeFish - tod.Hour) < 0) { ui.showHinweis("Du kannst nur alle 2 Stunden fischen.", 3.0F); } } else { ui.showHinweis("Mit einem Netz kannst du fischen.", 3.0F); } } } if(other.tag == "Searchable") { ui.showHinweis(true, "Mit 'E' den Gegenstand durchsuchen"); if(Input.GetKeyDown(KeyCode.E)) { GameObject collisionInfo = other.gameObject; string myitem = collisionInfo.GetComponent<SearchableScript>().search(); if(myitem != "") { inventory.addItemToInventory(myitem); ui.showHinweis("Du hast " + myitem + " gefunden.", 3.0F); } else { ui.showHinweis("Du hast nichts gefunden.", 3.0F); } } } }
// Update is called once per frame void Update() { if (citizen == null) { return; } switch (state) { case States.GoingToWorkplace: if (ArrivedAtTarget(wcc.InitialPosition)) { state = States.Available; } break; case States.Available: if (hasWorkToDo) { return; } if (!noTreesInArea) { Work(); } else { if (currentFindingTime < FindingTime) { currentFindingTime += Time.deltaTime; } else { currentFindingTime = 0f; Work(); } } break; case States.PathFinding: if (currenTree == null) { ResetWork(); } if (ArrivedAtTarget(currenTree)) { state = States.Working; AudioSource audio = currenTree.GetComponent <AudioSource>(); audio.volume = sm.volume; audio.Play(); //Debug.Log("Arived at tree"); } else { //Debug.Log("Going"); } break; case States.Working: if (currenTree == null) { ResetWork(); } if (currentChopingTime < ChopingTime) { currentChopingTime += Time.deltaTime; } else { TreeScript ts = currenTree.GetComponent <TreeScript>(); WoodGained = ts.Chop(WoodAccumulation); ts.ChopDownIfEmpty(); TreeChoped(); } break; case States.CarryingGoods: if (ArrivedAtTarget(wcc.InitialPosition)) { GoodsArrived(); state = States.Available; hasWorkToDo = false; } break; default: break; } }
void Update() { //All The Code For The Player Controls Moving, Attacking, etc.. #region Controls //Update This... //Movement Controls... var x = Input.GetAxis("Horizontal") * Time.deltaTime * xMod; var z = Input.GetAxis("Vertical") * Time.deltaTime * zMod; transform.Translate(x, 0, 0); transform.Translate(0, 0, z); //Sprinting, When Shift is held down the player moves faster if (Input.GetKey(KeyCode.LeftShift)) { xMod = 60f; zMod = 60f; isRunning = true; } //When The Player lets go of shift their speed returns to normal else if (Input.GetKeyUp(KeyCode.LeftShift)) { xMod = 15f; zMod = 15f; isRunning = false; } //If your mouse is locked this will let it "Escape" if (Input.GetKeyDown(KeyCode.Escape)) { if (Cursor.lockState == CursorLockMode.Locked) { Cursor.lockState = CursorLockMode.None; } } #endregion RaycastHit hit; float range = 4.5f; if (Input.GetMouseButtonDown(0)) { //If the player left clicks while having their mouse unlocked then lock their mouse if (Cursor.lockState == CursorLockMode.None) { Cursor.lockState = CursorLockMode.Locked; } //When The Player Presses Mouse 0 (Left Mouse Button) The Script Will Check If He's Looking At A Tree Then Figure Out What Tree It Is And "Attack it" if (Physics.Raycast(cam.transform.position, cam.transform.forward, out hit, range)) { TreeScript Target = hit.transform.GetComponent <TreeScript>(); if (Target != null) { Target.Punch(1); } else { } GameObject treeFX = Instantiate(treeImpactFX, hit.point, Quaternion.LookRotation(hit.normal)); Destroy(treeFX, 2f); } } }