- Home /
Create reset button to main camera
Hello, i have a question about the way to set button for reset main camera to original position, how i can do it, i already create the Reset button but now what i sould written inside button function to later when i click the button reset camera to original position. if have any idea to help how i can find it, will be helpful too much, thanks.
Answer by programmrzinc · Mar 11, 2013 at 07:20 PM
var OriginalPos : Vector3;
function Start(){
OriginalPos = MainCamera.camera.transform.position;
}
function ResetCamera(){
MainCamera.camera.transform.position = OriginalPos;
}
Simply Call the ResetCamera function inside your script to return the camera to the original camera position. Remember, this resets the MainCamera.
Well, is work but still have other problem, when i click on reset button he reset camera and work fine, but when i darg mouse after reset, just drag to space in unity the camera position change by creazy way, i dont know where is the error, also i use c sharp so if can help me by c sharp will more helpful, by the way i use rotate in my project using left click, thanks.
sure here is
using UnityEngine;
using System.Collections;
public class CameraRotate : $$anonymous$$onoBehaviour {
bool button = false;
public float hSliderValue = 0.5F;
public GUISkin color;
public AudioClip ClickButton;
public Camera teste;
Vector3 OriginalPos;
Quaternion OriginalRot;
public Camera $$anonymous$$ainCamera;
// Use this for initialization
void Start () {
// audio.clip = ClickButton;
OriginalPos = teste.transform.position;
// OriginalRot = teste.transform.rotation;
}
// Update is called once per frame
void Update () {
if(button) {
transform.RotateAround(Vector3.zero, Vector3.down, 25 * Time.deltaTime * hSliderValue);
}
}
void OnGUI () {
if(color != null){
GUI.skin = color;
}
GUI.Box(new Rect(15,9,100,150), "$$anonymous$$enu");
GUI.backgroundColor = Color.cyan;
// GUI.contentColor = Color.yellow;
if (GUI.Button(new Rect(30,40,70,30),"Iniciar")) {
button = true;
audio.clip = ClickButton;
audio.Play();
}
else if (GUI.Button(new Rect (30,80,70,30),"Pausa")){
button = false;
audio.clip = ClickButton;
audio.Play();
}
else if (GUI.Button(new Rect (30,120,70,30),"Reset")){
teste.transform.position = OriginalPos;
audio.clip = ClickButton;
audio.Play();
// Application.LoadLevel(0);
}
GUI.color = Color.white;
GUI.Box(new Rect(15,180,130,60), "Velocidade");
hSliderValue = GUI.HorizontalSlider(new Rect(30, 240, 100, 30), hSliderValue, 0F, 10.0F);
}
}
create a transform variable:
public Transform TargetObject;
and ins$$anonymous$$d of this:
transform.RotateAround(Vector3.zero, Vector3.down, 25 * Time.deltaTime * hSliderValue);
Replace it with this
transform.RotateAround(TargetObject.position, Vector3.down, 25 * Time.deltaTime * hSliderValue);
Thanks for quick respond, but is the same problem, didn't have change !!