I have some probelm, because I am begginer in scripting.
I have attached two cameras to one GameObject, both are childs for GameObjcet in hierarchy. I want to add script to GameObject, which allows me to change positions each of cameras simultaneously thanks to one slider.
For example:
I move slider, one of cameras move ten units to the right and simultaneously second camera move
the same number of units to the left.
Can anyone show me script, which let me do this thing?
// setup this links in editor, just drag your cameras from scene
public Camera leftCamera;
public Camera rightCamera;
void OnGUI () {
hSliderValue = GUI.HorizontalSlider (new Rect (25, 25, 100, 30), hSliderValue, 0.0f, 10.0f);
}
void Update() {
//transform.Translate (Vector3.right * hSliderValue * Time.deltaTime);
// Ive commented it because here your slider sets VELOCITY of camera movement, not POSITION
//if you want to slider sets POSITION - dont translate cameras every update
leftCamera.transform.localPosition = new Vector3(
leftCamera.transform.localPosition.x,
hSliderValue,
leftCamera.transform.localPosition.z);
rightCamera.transform.localPosition = new Vector3(
leftCamera.transform.localPosition.x,
-hSliderValue,
leftCamera.transform.localPosition.z);
// additionally you may have some multiplier for hSliderValue here to make camera move slower or faster
}