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 owags7 · Sep 21, 2012 at 04:11 AM · camerabuttonreference

Moving Camera with Rference to Button in seperate script

Hi, I am a noob at Unity. I have a problem where I am trying to get my camera to move to a certain x,y,z location, but only after a button is pushed.Then when its pushed a second time, thecamera moves back to its original spot. The problem is, this button is created in a differnet script because it also tells an object where to move. The script with the button:

 #pragma strict
 private var OutsideB: Transform;
 private var OriginalspotB : Transform;
 private var moved = false;
 
 private var stringToEdit : String = "This is Black";
 function Start () {
     OriginalspotB = transform.Find("/Black-start");
     OutsideB = transform.Find("/Black");
 }
 function OnGUI () {
     GUILayout.BeginHorizontal();
     GUILayout.Space(20);
     if(GUI.Button(Rect(0,0,150,50), "Examine Black")){
         if(moved){        
             moved = false;
         }
         else
         {
             moved = true;
         }
     }
     GUILayout.EndHorizontal();
 
     if(moved){
         // moved is true 
         transform.position = OutsideB.position;
         stringToEdit = GUI.TextArea (Rect (150, 175, 150, 50), stringToEdit, 20);
         camera.main.fieldOfView=60;
     }
     else{
         transform.position = OriginalspotB.position;
         
     }
     } 

This code that I have started is for the camera, with a second button (that I don't want)

 #pragma strict
 private var CameraB: Transform;
 private var OriginalC: Transform;
 private var moved = false;
 
 function Start () {
     OriginalC = transform.Find("/Main Camera Start");
     CameraB = transform.Find("/CameraBlack");
 }
 function OnGUI () {
     if(GUI.Button(Rect(0,50,150,50), "Examine Black")){
         if(moved){        
             moved = false;
         }
         else
         {
             moved = true;
         }
     }
     if(moved){
         // moved is true 
         transform.position = CameraB.position;
     }
     else{
         transform.position = OriginalC.position;
         
     }
     }

Any help on this?

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

2 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by FlyingOstriche · Sep 21, 2012 at 08:34 AM

update when moved changes

 camera.main.gameObject.SendMessage ("OnMoved", true/false   );  

in camera

 function OnMoved(var newMoved:boolean){
  moved=newMoved;
 }
Comment
Add comment · 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
0

Answer by owags7 · Sep 21, 2012 at 07:18 PM

I couldn't figure out exactly what you were trying to tell me to do. It still won't move the camera on button press. Any clarification?

Comment
Add comment · 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

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

10 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

Related Questions

Changing Cameras With One Button 4 Answers

Ramp Offset with Button press 1 Answer

How do I tell a button to move my camera!? 1 Answer

How can i keep this button pressed without acctualy doing it ? 0 Answers

Obect1 to Object2 to Object1 again. Object1 points to Object2. Same Script for both objects that uses gameObject. Why?[Solved] 2 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