added attack range check
This commit is contained in:
parent
bcdb2dcac0
commit
3d59441ad5
2 changed files with 19 additions and 2 deletions
|
@ -122,8 +122,12 @@ public class InputManagerScript : MonoBehaviour {
|
|||
Vector3 tpos = cursor.transform.position;
|
||||
switch (actionOption) {
|
||||
case 0:
|
||||
if (tmss.canAttackTo (gosel, (int)tpos.z, (int)tpos.x)) {
|
||||
tmss.attackTo (gosel, (int)tpos.z, (int)tpos.x);
|
||||
changeCursorColor (Color.cyan);
|
||||
} else {
|
||||
changeCursorColor (Color.red);
|
||||
}
|
||||
break;
|
||||
case 1:
|
||||
if (tmss.canMoveTo (gosel, (int)tpos.z, (int)tpos.x)) {
|
||||
|
|
|
@ -96,6 +96,19 @@ public class TurnManagerScript : MonoBehaviour {
|
|||
ub.stopMoveAct ();
|
||||
}
|
||||
|
||||
public bool canAttackTo(GameObject go, int i, int j) {
|
||||
UnitBehaviour ub = go.GetComponent<UnitBehaviour> ();
|
||||
int ra = ub.remainingActions;
|
||||
int pi = (int)go.transform.position.z;
|
||||
int pj = (int)go.transform.position.x;
|
||||
Vector2 diff = new Vector2(Math.Abs(pi - i), Math.Abs(pj - j));
|
||||
|
||||
if ((diff.x+diff.y) < ub.attackRange && ra > 0 && terrain [j, i] == 0)
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
public void attackTo(GameObject go, int i, int j) {
|
||||
int area = go.GetComponent<UnitBehaviour> ().attackArea;
|
||||
|
||||
|
|
Loading…
Reference in a new issue