I'm attempting to set the camera position in Unity through code. I have a simple 2D game and there's not much programming so far. I've attached a script to the camera, and in that script I've added this function:
void Update()
{
Transform transform = gameObject.GetComponent<Transform>();
Vector3 position = transform.position;
transform.position.Set(position.x + 1, position.y + 1, position.z);
}
My expectation is that this would create a smooth scrolling toward the bottom right corner. However, after checking via breakpoints, the transform.position always reports (0, 0, -10), even after setting it. The camera object is a stand alone and not a child of anything else in the scene. Am I setting the position wrong or getting the camera's GameObject wrong?
I've also tried:
- transform.SetPosition(); - doesn't exist
- transform.SetPositionAndRotation(); - no effect
- transform.position.x = 0; - not allowed
- transform.position = new Vector3(position.x + 1, position.y + 1, position.z) - no effect