Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by ahmedibrahim · Mar 11, 2013 at 06:28 PM · javascriptunitygui

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.

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
1

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.

Comment
Add comment · Show 6 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image ahmedibrahim · Mar 12, 2013 at 12:51 PM 0
Share

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.

avatar image programmrzinc · Mar 12, 2013 at 01:41 PM 0
Share

Can I see your script?

avatar image ahmedibrahim · Mar 12, 2013 at 01:52 PM 0
Share

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);
          
          
     
        }
     }
 
avatar image programmrzinc · Mar 12, 2013 at 04:33 PM 1
Share

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);
  
avatar image ahmedibrahim · Mar 12, 2013 at 04:44 PM 0
Share

Thanks for quick respond, but is the same problem, didn't have change !!

Show more comments

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

12 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Popup message in beginning 0 Answers

Texture2d.Readpixel slow down performance while stand-alone exe is minimize 0 Answers

Fade in Fade out in unity 1 Answer

nullreferenceexception object reference not set to an instance of an object 2 Answers

Hide the ImageTraget in Real world 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges