- Home /
Transform.position of camera not going to correct position
Whenever I hard code a position for the camera to transform to it will work. However, If I try to give a position based on a particular game object I'm referencing, then the camera position appears to move to a completely random location.
void Update()
{
if(nextScene) //Go to next scene (+1 scene).
{
sceneNumber++;
transform.position = new Vector3(scenePos[sceneNumber].position.x, scenePos[sceneNumber].position.y, scenePos[sceneNumber].position.z);
Debug.Log("pos is " + transform.position + "scene is" + sceneNumber);
nextScene = false;
}
any help is greatly appreciated!
What is scenePos
? Array / Dictionary of transforms? Is there a reason you aren't just assigning it as:
transform.position = scenePos[sceneNumber].position;
ins$$anonymous$$d of new vector and all the axis couldn't you just do transform.position = scenePos[sceneNumber].position?
The way your code is at the moment does look like it should work but idk..
Answer by djgraff1 · Apr 24, 2018 at 05:16 PM
Thanks Trey for the reply.
Yes its an Array. there are multiple scenes. Whenever I debug it shows the correct scene, however the position of x,y and z are different than the scene in question.
Scenes don't have positions, they're just collections of GameObjects. What are you thinking of when you're discussing scene position? Do you just have a set of predefined locations for each scene, like an overhead camera system for dungeon rooms?
I am making a point and click adventure. I simply have gameobjects that represent different locations that are all within the same scene. Sorry I shouldnt have referred to them as scenes. I am following this tutorial: https://www.youtube.com/watch?v=D5lY-lWlkn$$anonymous$$
Your answer
Follow this Question
Related Questions
Want to move object slowly to where the mouse clicks? 1 Answer
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
Only Allow One Click on GameObject? 2 Answers
Changing one script through another? 2 Answers