Remembering list of camera positions is not working
Hi all, i have a room with a few cubes. If i click on a cube i want to move the camera to the cube (i do this with SmoothDamp). This works great so far. But, when the player clicks the back button (from GUI), the camera has to move back to the previous clicked cube (if back is pressed again, it has to move to the previous position and so on). I tried this with a List. OnMouseDown adds a GameObject to that list. But the list does not stay filled. Very strange. I added a GUI.label to show the list.count. If i add 4 clicks the list should have 4 objects. But the GUI.label writes a 4 and a 1 on the same place. If i use a breakpoint, the first time it is called it actually has 4 objects. If i press play, the objects are gone and the count is 1. I dont get this.
I also tried to remember the GameObject names in an array but with with the array, the same things appears to be happening.
in code it looks a bit like this:
public GameObject target;
void Start () {
goList = new List<GameObject> ();
}
void Update() {
if (target != null) {
if (transform.position != target.transform.position) {
float newPositionZ = Mathf.SmoothDamp (transform.position.z, target.transform.position.z, ref yVelocity, smoothTime);
transform.position = new Vector3 (target.transform.position.x, target.transform.position.y, newPositionZ);
}
}
}
public void GotoTarget(GameObject aTarget)
{
goList.Add (aTarget);
target = aTarget;
}
The click cubes have a script to add themselve as a target.
public GameObject viewer;
void OnMouseDown(){
Camera.main.GetComponent<CameraController> ().GotoTarget (viewer);
}
So in short - Moving the camera is not the problem - Moving the camera trough a remembered list of positions is the problem
I hope someone can help me with this. Many thanks in advance.
Your answer
Follow this Question
Related Questions
List resulting in out of range 0 Answers
Getting the element that has the same element number on another list ? 2 Answers
I have trouble understanding arrays and enums. When and how? 0 Answers
Find the closest Enemy that has a tag added in a list? 1 Answer
How to make camera follow player from point to point 2 Answers