- Home /
Set camera position with: transform.position ? Changes back after done clicking.
Hi, I want to set my camera position when this button is pressed. My problem is not the button press and what not but rather keeping the position.
On the 3D button I have this in one part of the script:
void OnMouseDown() {
GameObject.Find("Main Camera").transform.position = new Vector3(0, 20, 0);
}
I am completely new to Unity and coding so I could be doing something silly, as when I click the button I see it change for a sec but then goes back as soon as im done clicking.
Thanks in advance!
That code is ok, there must be some other script that moves the camera, too.
Ah, I see. I just did this to solve it:
void On$$anonymous$$ouseDown() {
GameObject.Find("Player_ShotgunDude").GetComponent<Player$$anonymous$$ovement>().enabled=true;
GameObject.Find("$$anonymous$$ain Camera").transform.position = new Vector3(0, 20, 0);
GameObject.Find("$$anonymous$$ain Camera").GetComponent<CameraFollow>().enabled=true;
}
Not a pretty fix but it lets me have it disabled at first and enables correctly after the position change. :) Thanks for the heads up. Thought it would work as my camera follow doesnt change transform, just follows target.
Answer by Joshua-Classen · Oct 14, 2016 at 06:43 PM
Had other script affecting camera, had to enable it after making location changes.