/// <summary> /// This Function checks if the NPC has entered the trigger with an "Resource" or "ResourceCamp" tag /// with an extra check if the Task is set properly (and if it's in sync with what the NPC should be doing). /// If the tag of the trigger it collides with is "Resource", it'll set the isGathering bool to true, /// which will allow the resources, that are being carried by the NPC, to be added by 1 each second. /// If the tag is "ResourceCamp" however, it'll add the amount of carried resource to the right resource group. /// (So, if 20 wood is being carried, the player will receive 20 Wood rather than 20 Steel, as it should obviously) /// </summary> public void OnTriggerEnter(Collider other) { GameObject hitObject = other.gameObject; if (hitObject.tag == "Resource" && task == TaskList.Gathering) { isGathering = true; heldResourceType = hitObject.GetComponent <NodeManager>().resourceType; } else if (hitObject.tag == "ResourceCamp" && task == TaskList.Delivering) { if (heldResourceType == NodeManager.ResourceTypes.Wood) { PlayerStats.wood += heldResource; } else if (heldResourceType == NodeManager.ResourceTypes.Stone) { PlayerStats.stone += heldResource; } else if (heldResourceType == NodeManager.ResourceTypes.Steel) { PlayerStats.steel += heldResource; } heldResource = 0; task = TaskList.Gathering; agent.destination = targetNode.transform.position; } }
public void OnTriggerEnter(Collider other) { GameObject hitObject = other.gameObject; if (hitObject.tag == "Resource" && task == TaskList.Gathering) { Debug.Log("Is in Resource trigger"); isGathering = true; hitObject.GetComponent <NodeManager>().gatherers++; heldResourceType = hitObject.GetComponent <NodeManager>().resourceType; } else if (hitObject.tag == "Drops" && task == TaskList.Delivering) { if (RM.stone >= RM.maxStone) { task = TaskList.Idle; } else { RM.stone += heldResource; heldResource = 0; task = TaskList.Gathering; agent.destination = targetNode.transform.position; } } }
private void OnTriggerEnter(Collider other) { GameObject hitObject = other.gameObject; if (hitObject.tag == "Resource") { isGathering = true; hitObject.GetComponent <NodeManager>().gatherers++; heldResourceType = hitObject.GetComponent <NodeManager>().resourceType; } }
// Allows collider of resources public void OnTriggerEnter(Collider other) { GameObject hitObject = other.gameObject; if (hitObject.tag == "Resource" && hitObject.gameObject == targetNode && gameObject.GetComponent <UnitController>().unitType == "Worker") { isGathering = true; harvestScript = targetNode.GetComponent <NodeManager>(); harvestSpeed = harvestScript.harvestTime; heldResourceType = hitObject.GetComponent <NodeManager>().resourceType; StartCoroutine(Tick()); } else if (hitObject.tag == "Foundation" && hitObject.gameObject == targetNode && gameObject.GetComponent <UnitController>().unitType == "Worker") { isBuilding = true; hitObject.GetComponent <FoundationController>().builders++; buildScript = targetNode.GetComponent <FoundationController>(); buildSpeed = buildScript.buildTime; StartCoroutine(Tick()); } else if (hitObject.tag == "Player 1" && task == ActionList.Delivering && gameObject.GetComponent <UnitController>().unitType == "Worker") { if (heldResourceType == NodeManager.ResourceTypes.Skymetal) { DropSkyMetal(); } if (heldResourceType == NodeManager.ResourceTypes.Wood) { DropWood(); } if (heldResourceType == NodeManager.ResourceTypes.Iron) { DropIron(); } if (heldResourceType == NodeManager.ResourceTypes.Stone) { DropStone(); } if (heldResourceType == NodeManager.ResourceTypes.Gold) { DropGold(); } if (heldResourceType == NodeManager.ResourceTypes.Food) { DropFood(); } } }
public void Gather() { isGathering = true; if (!isGather) { TargetNode.GetComponent <NodeManager>().gatherers++; isGather = true; } heldResourceType = TargetNode.GetComponent <NodeManager>().resourceType; GetComponent <NavMeshObstacle>().enabled = true; GetComponent <NavMeshAgent>().enabled = false; }
//Sets the colonist to be gathering public void Gather() { isGathering = true; //Allows the colonist to gather if (!isGatherer) //Is the colonist a gatherer? { targetNode.GetComponent <NodeManager>().gatherers++; //Add the colonist to the node's gatherers isGatherer = true; //Sets the colonist to be a gatherer } heldResourceType = targetNode.GetComponent <NodeManager>().resourceType; //Sets the resource that the colonist is holding to the same as the node GetComponent <NavMeshObstacle>().enabled = true; //Enables the NavMeshObstacle component GetComponent <NavMeshAgent>().enabled = false; //Disable the NavMeshAgent component }
public void UpdateUnitPanel() { if (RC.artisanArmourSmithing) { UI.armour1.GetComponent <Image>().color = new Color32(255, 165, 0, 255); UI.armour2.GetComponent <Image>().color = new Color32(255, 165, 0, 255); UI.armour3.GetComponent <Image>().color = new Color32(255, 165, 0, 255); UI.armour4.GetComponent <Image>().color = new Color32(255, 165, 0, 255); UI.armour5.GetComponent <Image>().color = new Color32(255, 165, 0, 255); } else if (RC.basicArmourSmithing) { UI.armour1.GetComponent <Image>().color = new Color32(114, 160, 193, 255); UI.armour2.GetComponent <Image>().color = new Color32(114, 160, 193, 255); UI.armour3.GetComponent <Image>().color = new Color32(114, 160, 193, 255); UI.armour4.GetComponent <Image>().color = new Color32(114, 160, 193, 255); UI.armour5.GetComponent <Image>().color = new Color32(114, 160, 193, 255); } else { UI.armour1.GetComponent <Image>().color = new Color32(205, 127, 50, 255); UI.armour2.GetComponent <Image>().color = new Color32(205, 127, 50, 255); UI.armour3.GetComponent <Image>().color = new Color32(205, 127, 50, 255); UI.armour4.GetComponent <Image>().color = new Color32(205, 127, 50, 255); UI.armour5.GetComponent <Image>().color = new Color32(205, 127, 50, 255); } if (unitScript.armour <= 0.0f) { UI.armour1.alpha = 0; UI.armour2.alpha = 0; UI.armour3.alpha = 0; UI.armour4.alpha = 0; UI.armour5.alpha = 0; } else if (unitScript.armour <= 1.0f) { UI.armour1.alpha = 1; UI.armour2.alpha = 0; UI.armour3.alpha = 0; UI.armour4.alpha = 0; UI.armour5.alpha = 0; } else if (unitScript.armour <= 2.0f) { UI.armour1.alpha = 1; UI.armour2.alpha = 1; UI.armour3.alpha = 0; UI.armour4.alpha = 0; UI.armour5.alpha = 0; } else if (unitScript.armour <= 3.0f) { UI.armour1.alpha = 1; UI.armour2.alpha = 1; UI.armour3.alpha = 1; UI.armour4.alpha = 0; UI.armour5.alpha = 0; } else if (unitScript.armour <= 4.0f) { UI.armour1.alpha = 1; UI.armour2.alpha = 1; UI.armour3.alpha = 1; UI.armour4.alpha = 1; UI.armour5.alpha = 0; } else if (unitScript.armour <= 5.0f) { UI.armour1.alpha = 1; UI.armour2.alpha = 1; UI.armour3.alpha = 1; UI.armour4.alpha = 1; UI.armour5.alpha = 1; } // UI Functions // unitScript = selectedObj.GetComponent<UnitController>(); Image icon = unitIcon.GetComponent <Image>(); icon.sprite = unitScript.unitIcon; HB.maxValue = unitScript.maxHealth; HB.value = unitScript.health; EB.maxValue = unitScript.maxEnergy; EB.value = unitScript.energy; healthDisp.text = "HEALTH: " + unitScript.health; energyDisp.text = "ENERGY: " + unitScript.energy; nameDisp.text = unitScript.unitName; unitName.text = unitScript.unitType; rankDisp.text = unitScript.unitRank; killDisp.text = "Kills: " + unitScript.unitKills; weaponDisp.text = unitScript.weapon; armourDisp.text = unitScript.armourType; NodeManager.ResourceTypes resourceType = selectedInfo.heldResourceType; itemDisp.text = resourceType + ": " + selectedInfo.heldResource; }
// Update is called once per frame void Update() { if (health <= 0) { health = 0; gameObject.GetComponent <NavMeshAgent>().enabled = false; if (unitType == "Worker" || unitType == "Footman" || unitType == "Swordsman" || unitType == "Archer" || unitType == "Wizard") { anim.SetInteger("condition", 10); isDead = true; UnitSelection.isBuilding = false; UnitSelection.isGathering = false; UnitSelection.isFollowing = false; UnitSelection.isAttacking = false; UnitSelection.isMeleeing = false; } RM.housing -= 1.0f; } if (!isDead) { resourceType = UnitSelection.heldResourceType; heldResource = UnitSelection.heldResource; //For attacking anim.SetFloat("Speed", agent.velocity.magnitude); newTask = UnitSelection.task; // Setting animation state if (unitType == "Worker") { if (heldResource > 0) { if (resourceType == NodeManager.ResourceTypes.Wood) { if (UnitSelection.isBuilding && newTask == ActionList.Building || UnitSelection.isGathering && newTask == ActionList.Gathering || UnitSelection.isMeleeing) { anim.SetInteger("condition", 5); } else if (!UnitSelection.isBuilding && !UnitSelection.isGathering || newTask != ActionList.Building && newTask != ActionList.Gathering) { anim.SetInteger("condition", 4); } } else { if (UnitSelection.isBuilding && newTask == ActionList.Building || UnitSelection.isGathering && newTask == ActionList.Gathering || UnitSelection.isMeleeing) { anim.SetInteger("condition", 3); } else if (!UnitSelection.isBuilding && !UnitSelection.isGathering || newTask != ActionList.Building && newTask != ActionList.Gathering) { anim.SetInteger("condition", 2); } } } else { if (UnitSelection.isBuilding && newTask == ActionList.Building || UnitSelection.isGathering && newTask == ActionList.Gathering || UnitSelection.isMeleeing) { anim.SetInteger("condition", 1); } else if (!UnitSelection.isBuilding && !UnitSelection.isGathering || newTask != ActionList.Building && newTask != ActionList.Gathering) { anim.SetInteger("condition", 0); } } } else if (unitType == "Footman" || unitType == "Swordsman" || unitType == "Archer" || unitType == "Wizard") { if (UnitSelection.isMeleeing) { anim.SetInteger("condition", 1); } else if (!UnitSelection.isMeleeing) { anim.SetInteger("condition", 0); } } } }