private void Update() { if ((Input.GetButtonDown("next") && !findingPath && moveDone && !actionTime && manager.get_turn()) || (manager.switchAction)) { print("CHANGING PATH"); if (currentUnit == UNITS.transform.childCount - 1) { currentUnit = 0; } else { currentUnit++; } if (UNITS.transform.childCount > 0) { seeker = UNITS.transform.GetChild(currentUnit); } manager.switchAction = false; manager.switchDestroy(); } if (Input.GetButtonDown("prev") && !findingPath && moveDone && !actionTime && manager.get_turn()) { print("CHANGING PATH"); if (currentUnit == 0) { currentUnit = UNITS.transform.childCount - 1; } else { currentUnit--; } seeker = UNITS.transform.GetChild(currentUnit); } }
// Update is called once per frame void Update() { if ((Input.GetButtonDown("next") && !actionTime && moveDone && manager.get_turn()) || (manager.switchAlly)) { print("CHANGING ACTION"); if (currentUnit == UNITS.transform.childCount - 1) { currentUnit = 0; } else { currentUnit++; } if (UNITS.transform.childCount > 0) { unit = UNITS.transform.GetChild(currentUnit).gameObject; } yourStats = unit.GetComponent <UnitStats>(); svd = unit.transform.GetChild(2).gameObject; ps = svd.GetComponent <PlayParticle>(); manager.switchAlly = false; manager.switchDestroy(); return; } if (Input.GetButtonDown("prev") && !actionTime && moveDone && manager.get_turn()) { print("CHANGING ACTION"); if (currentUnit == 0) { currentUnit = UNITS.transform.childCount - 1; } else { currentUnit--; } unit = UNITS.transform.GetChild(currentUnit).gameObject; yourStats = unit.GetComponent <UnitStats>(); svd = unit.transform.GetChild(2).gameObject; ps = svd.GetComponent <PlayParticle>(); return; } //right click to shoot at target if (actionTime) { if (Input.GetButtonDown("Fire2")) { RaycastHit hit; if (Physics.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition), out hit, Mathf.Infinity)) { //layer 10 is an enemy and raycast from this player to the enemy also succeeds if (hit.collider.gameObject.layer == 10) { tgt = hit.collider.gameObject; RaycastHit hit2; //another raycast from this position to the enemy to check line of sight if (Physics.Raycast(unit.transform.position, (tgt.transform.position - unit.transform.position), out hit2, Mathf.Infinity)) { //attack code if (hit2.collider.gameObject.layer == 10) { unit.transform.LookAt(tgt.transform); //call particle scripts //Debug.Log(ps); ps.playParticle(); //wait after shooting enemyStats = tgt.GetComponent <UnitStats>(); float hitChance = yourStats.accuracy - enemyStats.evasion; bool RNGSuccess = Random.Range(0.0f, 101.0f) <= hitChance; //Debug.Log("hit chance is " + hitChance); if (RNGSuccess) { // Debug.Log("you hit the enemy for " + yourStats.weaponDamage + " damage."); enemyStats.takeDamage(yourStats.weaponDamage); //Debug.Log("enemey health is " + enemyStats.health); } else { missed.SetActive(true); } //prevent second shot actionTime = false; StartCoroutine(ExampleCoroutine()); } } //rotate the player to shoot at the enemy //calculate hit chance //shoot } } } if (Input.GetButtonDown("Jump")) { pathfinder.setAction(false); manager.set_turn(false); actionTime = false; playerMove.playerActionDone = true; } } }
// Update is called once per frame void Update() { if (manager.get_turn() && playerActionDone && moveRadius != null) { moveRadius.SetActive(true); } if ((Input.GetButtonDown("next") && moveDone && manager.get_turn() && playerActionDone) || (manager.switchChar)) { print("CHANGING MOVEMENT"); player.transform.GetChild(0).gameObject.SetActive(false); player.transform.GetChild(1).gameObject.SetActive(false); if (currentUnit == UNITS.transform.childCount - 1) { currentUnit = 0; } else { currentUnit++; } if (UNITS.transform.childCount > 0) { player = UNITS.transform.GetChild(currentUnit).gameObject; moveRadius = UNITS.transform.GetChild(currentUnit).GetChild(0).gameObject; } lastPosition = player.transform.position; player.transform.GetChild(0).gameObject.SetActive(true); player.transform.GetChild(1).gameObject.SetActive(true); manager.switchChar = false; manager.switchDestroy(); return; } if (Input.GetButtonDown("prev") && moveDone && manager.get_turn() && playerActionDone) { print("CHANGING MOVEMENT"); player.transform.GetChild(0).gameObject.SetActive(false); player.transform.GetChild(1).gameObject.SetActive(false); if (currentUnit == 0) { currentUnit = UNITS.transform.childCount - 1; } else { currentUnit--; } player = UNITS.transform.GetChild(currentUnit).gameObject; lastPosition = player.transform.position; moveRadius = UNITS.transform.GetChild(currentUnit).GetChild(0).gameObject; player.transform.GetChild(0).gameObject.SetActive(true); player.transform.GetChild(1).gameObject.SetActive(true); return; } //move to the clicked location if (Input.GetButtonDown("Fire1") && moveDone && manager.get_turn() && playerActionDone) { RaycastHit hit; if (Physics.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition), out hit, Mathf.Infinity)) { //walkable layer //Debug.Log(hit.collider.gameObject.layer); if (hit.collider.gameObject.layer == 8) { setDestination(hit.point); performedAction = true; playerActionDone = false; moveRadius.SetActive(false); distanceTraveled = 0.0f; } } } //move to the clicked location if (Input.GetButtonDown("Fire2") && moveDone && manager.get_turn() && playerActionDone) { moveDone = true; performedAction = true; playerActionDone = false; moveRadius.SetActive(false); distanceTraveled = 0.0f; } if (performedAction && moveDone) { //shoot/ability/etc. alliedAI.alliedAction(); //wait for manager to set turn in alliedai performedAction = false; } //actually move the unit if (waypointCurrent != null && !moveDone) { alliedAI.setMove(); pathfinder.setDone(false); pathfinder.seeker.transform.position = Vector3.MoveTowards(pathfinder.seeker.transform.position, waypointCurrent.worldPosition, .1f); //get to the next waypoint if it is in bounds distanceTraveled += Vector3.Distance(player.transform.position, lastPosition); lastPosition = player.transform.position; if (distanceTraveled >= maxDistance) { index = waypoints.Count; distanceTraveled = 0.0f; } if (pathfinder.seeker.transform.position == waypointCurrent.worldPosition) { index++; if (index < waypoints.Count) { //Debug.Log(index); //Debug.Log(waypoints.Count); waypointCurrent = waypoints[index]; } else { waypointCurrent = null; moveDone = true; pathfinder.setDone(true); pathfinder.setAction(true); distanceTraveled = 0.0f; } } } //transform.Translate(Vector3.forward * Time.deltaTime); }