public void Setup() { // Get references to the components. m_Movement = m_Instance.GetComponent <TankMovement> (); m_Shooting = m_Instance.GetComponent <TankShooting> (); m_Controller = m_Instance.GetComponent <Tank>(); m_CanvasGameObject = m_Instance.GetComponentInChildren <Canvas> ().gameObject; m_Controller.getColor(m_PlayerColor); m_AgentGOAP = m_Instance.GetComponent <AgentGOAP>(); // Set the player numbers to be consistent across the scripts. //m_Movement.m_PlayerNumber = m_PlayerNumber; m_Shooting.m_PlayerNumber = m_PlayerNumber; // Create a string using the correct color that says 'PLAYER 1' etc based on the tank's color and the player's number. m_ColoredPlayerText = "<color=#" + ColorUtility.ToHtmlStringRGB(m_PlayerColor) + ">PLAYER " + m_PlayerNumber + "</color>"; // Get all of the renderers of the tank. MeshRenderer[] renderers = m_Instance.GetComponentsInChildren <MeshRenderer> (); // Go through all the renderers... for (int i = 0; i < renderers.Length; i++) { // ... set their material color to the color specific to this tank. renderers[i].material.color = m_PlayerColor; } }
public override bool perform(GameObject agent) { Tank currentA = agent.GetComponent <Tank>(); AgentGOAP currentGOAP = agent.GetComponent <AgentGOAP>(); Debug.Log("Attack"); //Find a node if we don't have one and get the path to it if (targetNode == null) { //Finding a node in circle around the enemy tank var radius = 3; var vector2 = Random.insideUnitCircle.normalized * radius; var targetPos = currentA.EnemyTank.transform.position + new Vector3(vector2.x, 0, vector2.y); targetNode = currentA.CalculatePath(targetPos); Debug.Log(targetNode.transform.position); //If you can't see the enemy and we know his last position, search in the area around last know pos } else if (currentA.knownEnemyPosition != null && !currentA.canSeeEnemy && currentA.findNodeCloseToPosition(transform.position) == targetNode) { Debug.Log("Last position"); float randomX = Random.Range(-10, 10); float randomZ = Random.Range(-10, 10); Vector3 targetPos = currentA.knownEnemyPosition + new Vector3(randomX, 0, randomZ); targetNode = currentA.CalculatePath(targetPos); searchCount++; //If we don't have the last positon and can't see the enemy abort plan } else if (currentA.knownEnemyPosition == Vector3.zero && !currentA.canSeeEnemy) { return(false); } else if (currentA.findNodeCloseToPosition(transform.position) == targetNode) { reachedNode = true; } //If we have searched 5 locations abort plan if (searchCount > 5) { return(false); } //If health is under accepted level abort plan (bad variable name) return(currentA.healthOver10); }