Hi there,
I’m working on a 3d model that needs parts to be set to a ‘disassembled’ position in the beginning, that is, away from their original position. The parts are then made visible as the user goes along and completes the assembly steps. Each step is represented by a state, and at the end of each state, the corresponding parts are back in their ‘assembled/original’ position.
This script attaches to all such objects:
public class Behaviour : MonoBehaviour {
public float x_diff = 0;
public float y_diff = 0;
public float z_diff = 0;
// Starting/Ending points
private Vector3 move;
private void Awake()
{
move = new Vector3(x_diff, y_diff, z_diff);
}
public void Start()
{
// THIS WORKS
transform.Translate(move);
}
public void show()
{
gameObject.SetActive(true);
}
public void hide()
{
gameObject.SetActive(false);
}
public void move_out()
{
// THIS DOESN'T
transform.Translate(move);
}
public void move_back()
{
transform.Translate(-1 * move);
}
}
Each state calls these functions as needed.
Here’s the problem:
- the function move_out() is not reliably moving the objects. Some move, others don’t.
- when this happens, move_back() ends up placing objects further away in the other direction.
Calling move_out() in Start() is an option but it only runs once, so the state is not able to ‘re-initialize’ the objects back.
Do I need to figure out a way to call move_out() and move_back() in Update() ?
Any suggestions?