How do I add to a vector3 value? !!!Urgent!!!

I need to add a variable to a Vector3.up value, here is an example of what I want to do.

//working
if (followYAxis == true) 
{
cam.transform.position.y = new Vector3 (0,  playerController.transform.position.y, 0);
}
//not working
if (followYAxis == true) 
{
cam.transform.position.y = new Vector3 (0,  playerController.transform.position.y += camHeightOffset, 0);
}

Uhm, from your code it’s not really clear what you actually want to do. Both examples you’ve given won’t work and won’t even compile in C#.

Apart from the fact that you can’t assign a component(x, y or z) of the position property seperately due to the value type - property problem, you can’t assign a Vector3 value to a float variable.

If you just want to add a certain amount to along the Vector3.up axis you can do:

cam.transform.position = playerController.transform.position + Vector3.up * camHeightOffset;

or

Vector3 temp = playerController.transform.position;
temp.y += camHeightOffset;
cam.transform.position = temp;

This will set the “cam” object at the same position as the player controller but offset by camHeightOffset.

You should use “cam.transform.position” not “cam.transform.position.y”

 if (followYAxis == true) 
 {
 cam.transform.position = new Vector3 (cam.transform.x ,  playerController.transform.position.y + camHeightOffset, cam.transform.z);
 }