Hello everyone! I have run into a bit of a snag in my programming efforts and am seeking some advice. Any help is much appreciated!
General Overview of problem
I am instantiating a cube on a grid when dragging a “card” onto the grid. The goal is on select, allow player to move this object “x” amount depending on how many movement points the object has (represented as variable mp in script below) Currently, after i drag a card onto the grid and a cube is instantiated, i can select the cube which changes the “selected” var to true and enables me to move the block using the arrow keys. The problem is when i press an arrow key, it moves along the correct plane, but moves until the mp var shows negative numbers, sometimes as high as -99. The interesting thing is when i take the “selected” var out of the equation, it worked fine. Obviously i wanted to add a selected var, and in the update function used an if statement that checked for it to be true, and when true, ran function move(), which is comprised of the gridmove script. I have been staring at this forever and cant seem to wrap my head around what the problem is. Any help is much appreciated 
#pragma strict
var walkSpeed : float = 1.0;
var runSpeed : float = 2.0;
var gridSize : int = 1;
enum Orientation {Horizontal, Vertical}
var gridOrientation = Orientation.Horizontal;
var allowDiagonals = false;
var correctDiagonalSpeed = true;
private var input = Vector2.zero;
var character: Character;
var selected: boolean = false;
var mp: int;
function Start ()
{
character = GetComponentInChildren(Character);
mp = character.getMovementPoints();
}
function Update()
{
if (selected)
{
Move();
}
}
function Move()
{
var myTransform = transform;
var startPosition : Vector3;
var endPosition : Vector3;
var t : float;
var tx : float;
var moveSpeed = walkSpeed;
while (mp > 0)
{
Debug.Log("first while loop passes");
while (input == Vector2.zero)
{
Debug.Log("second while loop passes");
GetAxes();
tx = 0.0;
yield;
}
transform.forward = Vector3.Normalize(new
Vector3(Input.GetAxis("Horizontal"), 0f, Input.GetAxis("Vertical")));
startPosition = myTransform.position;
endPosition = gridOrientation == Orientation.Horizontal?
Vector3(Mathf.Round(myTransform.position.x), 0.0,
Mathf.Round(myTransform.position.z)) +
Vector3(System.Math.Sign(input.x)*gridSize, 0.0, System.Math.Sign(input.y)
*gridSize)
:
Vector3(Mathf.Round(myTransform.position.x),
Mathf.Round(myTransform.position.y), 0.0) +
Vector3(System.Math.Sign(input.x)*gridSize, System.Math.Sign(input.y)
*gridSize, 0.0);
t = tx;
while (t < 1.0)
{
//moveSpeed = Input.GetButton("Run")? runSpeed : walkSpeed;
t += Time.deltaTime * (moveSpeed/gridSize) * (correctDiagonalSpeed
&& input.x != 0.0 && input.y != 0.0? .7071 : 1.0);
myTransform.position = Vector3.Lerp(startPosition, endPosition, t);
yield;
}
tx = t - 1.0;
Time.deltaTime variance
// Used to prevent slight visual hiccups on "grid lines" due to
GetAxes();
mp -= 1;//added to subtract one movement from moved character
}
}
function GetAxes ()
{
input = Vector2(Input.GetAxis("Horizontal"), Input.GetAxis("Vertical"));
if (allowDiagonals)
return;
if (Mathf.Abs(input.x) > Mathf.Abs(input.y))
input.y = 0.0;
else
input.x = 0.0;
}
function isSelected()
{
selected = true;
}
function deselect()
{
selected = false;
}
Again, any help is much appreciated. This has been driving me insane.
You should just call Move from Start().