Moving one gameobject to another being inconsistent.
So here what we are doing is trying to move the GameObject "Infantry" with the sprite "Rifleman" to the GameObject "cursor". The idea is when the move button is pressed, toggleMove is made true, activating the chunk of code in Update. It checks if the sprite is still Rifleman, then makes our keyboard-controlled cursor able to move freely . The Infantry GameObject is moved to the cursor GameObject only if they aren't both in the same place, and the "Select" button is pressed. Then it changes the sprite, and resets toggleMove.
The problem is that often, when the infantry is told to move, the sprite changes BUT the infantry doesn't move. Sometimes it all works, however. There is no rhyme or rhythm to when it works or doesn't; it isn't based on position, because it can move to specific places sometimes and not others.
Excuse the mess, we are new at this. Thank you
public void MoveButton() {
toggleMove = true;
}
void Update() {
while (toggleMove == true && InfantrySprite.sprite == Rifleman) {
GameObject.Find ("cursor").GetComponent<CursorMove> ().enabled = true;
GameObject.Find ("Canvas").GetComponent<Canvas> ().enabled = false;
if (GameObject.Find ("Infantry").transform.position != GameObject.Find ("cursor").transform.position && Input.GetButtonDown ("Select")) {
GameObject.Find ("Infantry").transform.position = GameObject.Find ("cursor").transform.position;
InfantrySprite.sprite = doneRifleman;
toggleMove = false;
}
break;
}
}
Your answer
Follow this Question
Related Questions
Need help with limited movement with mathf clamp 2 Answers
Rigidbody movement: Changing the Y of transform.position makes my character stutter 0 Answers
Move a object along a vector 1 Answer
Why Can't I get 2D object to Move? 1 Answer
How to make an object move in the direction another object is facing on 2 axis? 1 Answer