- Home /
Code Executing Incorrectly in Update()
I'm getting a really strange issue. The following code executes perfectly fine if called from Start(), but only the Debug actions execute if called from Update(). I've tried limiting frequency, only calling it once or every few frames, but the result is the same. Is there something included below that would cause fields to be skipped in Update()?
private void MoveUp() {
Debug.Log("1");
Vector3 leftNewPosition = tileList[2].transform.position;
leftNewPosition.y += spriteHeight * 2;
tileList[2].transform.position = leftNewPosition;
Transform leftMoving = tileList[2];
tileList.RemoveAt(2);
tileList.Insert(0, leftMoving);
Debug.Log("2");
Vector3 rightNewPosition = tileList[3].transform.position;
rightNewPosition.y += spriteHeight * 2;
tileList[3].transform.position = rightNewPosition;
Transform rightMoving = tileList[3];
tileList.RemoveAt(3);
tileList.Insert(1, rightMoving);
Debug.Log("End");
}
Edit: I think I've found the issue, but I still don't understand what is causing it or how to approach it. It appears to be moving the transforms for the sprites, but the objects don't visibly move. Any location calculations use the new location, but the object is still visibly at the old location, and the transform component still reads off the old coordinates. Again, this only happens when the method is called from update, but happens exactly as desired if called from Start().
Answer by Piranha_48 · Sep 28, 2017 at 07:28 PM
Found my issue. Problem was remaking the GameObject's prefab had created multiple copies of the script on it. Both were trying to update the object's location at the same time.
Answer by nzmichael118 · Sep 12, 2017 at 11:50 PM
you need a f after some numbers
The type of the literals isn't what's causing my problem, though. They cast just fine without 'f' in a circumstance where they have another variable of the expected type present in the equation. The code compiles fine, and performs the desired results if called from Start(), but I need it to happen from Update(), which is where the issue is co$$anonymous$$g from.
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
Parsing Error, code in android for a button 2 Answers
UNITY_MVP_MATRIX error when downloading A* Pathfinding 1 Answer