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
-1
Question by Xentarok · Aug 09, 2013 at 06:55 PM · cameraguilerp

[Solved]GUI button problem.

Hello.

I have a script which makes it so, that when you click on the GUILayout button the camera lerps from one position to another. The problem is, that for some reason it doesn't work. I have no errors at all.

 using UnityEngine;
 using System.Collections;
 
 public class PlaGUI : MonoBehaviour {
     
     private Vector3 DefPos;
     
     public int fontSize;
     
     private Camera Cam;
     
     private float t;
     
     private float MoveChange = 0f;
     
     void Start () {
     
         
         
         
     }
     
     
     void OnMouseUp(){
         
         MoveChange++;
         
     }    
     
     
     void OnGUI(){
         
         if(MoveChange == 1f){
         
             GUI.skin.label.fontSize = GUI.skin.box.fontSize = GUI.skin.button.fontSize = fontSize;
             
             DefPos = new Vector3(0,600,0);
         
         GUILayout.BeginArea(new Rect(Screen.width /2 - 13, Screen.height/2 + transform.localScale.x, 26, 400));
         
         
         if(GUILayout.Button("X",GUILayout.Height(26f))){
             
         Cam = Camera.main;
 
             
             t+=Time.deltaTime;
             
             Quaternion Rot = Quaternion.Euler(90,0,0);        
             
             Cam.transform.position = Vector3.Lerp(Cam.transform.position, DefPos, t*1.5f);    
             Cam.transform.rotation = Quaternion.Lerp (Cam.transform.rotation, Rot, t*1.5f);
             
                 
                 
             }
         
         
         GUILayout.EndArea();
     
         }
         
         }    
     
     
     void Update () {
         
         if(MoveChange == 2f){
             
         MoveChange = 1f;    
             
         }    
         
     }
 }


[Edit] My fault, another script was interrupting, now it's working.

Thanks in advice for any answears, and forgive me if I'm missing something obvious here.

-Xentarok

P.S: If you have any questions about write them down in the comments.

P.S.2: Also, is there a way to have GUI button be on the edge of GameObject, because

             GUILayout.BeginArea(new Rect(Screen.width /2 - 13, Screen.height/2 + transform.localScale.x, 26, 400));

is unfortunately not working.

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
0

Answer by Sundar · Aug 09, 2013 at 07:54 PM

Try this

MoveChange += 0.1f;

Comment
Add comment · Show 3 · 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 Xentarok · Aug 09, 2013 at 08:07 PM 0
Share

Still nothing.

avatar image Sundar · Aug 09, 2013 at 08:18 PM 0
Share

Ok $$anonymous$$oveChange += 1.0f; Can you try without deltatime in lerp like Camera.main.transform.position = Vector3.Lerp(Camera.main.transform.position, DefPos, 1.5f);
Camera.main.transform.rotation = Quaternion.Lerp (Camera.main.transform.rotation, Rot, 1.5f);

And also Check camera position after selecting button

avatar image Xentarok · Aug 09, 2013 at 08:23 PM 0
Share

Okay, I found out what is wrong. One of my other scripts is interrupting the camera movement, keeping it in the same place.

I'm fixing it now, but thanks for the answear anyway!

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

15 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 avatar image avatar image avatar image

Related Questions

nodal camera positions 1 Answer

3D menu camera rotation issue. 0 Answers

How to lerp between cameras on a UI button click? 2 Answers

Transition current camera rotation to 0,0,0 1 Answer

How to randomly chenge camerabackground color every 5 seconds? 1 Answer


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