Hello,
I’m developing my first project in unity, is a architectural visualization.
I’m being felt inspired in the projects of the Fractal Zero, that are excellent.
I’m with some doubts and would like the aids them experts in unity.
The doubts are:
- To write one script to place zoom of camera
- To write one script to modify the height of camera
I’m sorry for my english, but i’m from Brazil…
Thanks all,
Alex
You can change the field of view using the camera functions:
http://unity3d.com/Documentation/ScriptReference/Camera-fieldOfView.html
You probably want to use some input functions to modify it eg.
http://unity3d.com/Documentation/ScriptReference/Input.GetAxis.html
or
http://unity3d.com/Documentation/ScriptReference/Input.GetButtonDown.html
- To change the height of the camera. Simply move the camera up.
Attach a script to the camera, which is a child of the fps controller game object in the hierarchy view.
The following script will move the camera up by one meter. If you are using the fps controller prefab, this will only change the height camera the character will still walk around in the same way.
function Start
{
transform.Translate(0, 1, 0);
}
You probably want to not do this in start but instead in the Update function checking for a button similar to this:
http://unity3d.com/Documentation/ScriptReference/Input.GetButtonDown.html
The height ok, functions perfectly, thanks.
But zoom of camera, I am not obtaining with that zoom goes magnifying
or diminishing gradual when the user pressures one of the keyboard
keys.
var horizontalSpeed = 0.1;
var verticalSpeed = 10;
function Update () {
//if (Input.GetKeyDown (".")) {
// print (". key was pressed down");
//}
//if (Input.GetKeyDown (",")) {
// print (", key was pressed down");
//}
var h = horizontalSpeed * Input.GetAxis ("altura");
var v = verticalSpeed * Input.GetAxis ("zoom");
transform.Translate (0, h, 0);
transform.camera.fieldOfView = 60 + v;
}
Some suggestion?
Thanks
Alex
Try something like
transform.camera.fieldOfView += v;
… which will accumulate the changes instead of
transform.camera.fieldOfView = 60 + v;
… which sets the field of view to 60 plus the current value of the input axis.