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 Blink · Sep 09, 2012 at 07:37 PM · camerachangeclick3dtextmainmenu

Change camera on text click?

For my main menu of my game I thought it would be good if I had different 3D texts saying select mission, options and quit, and if you click one of them it changes do a different camera or changes the current camera to a different position showing more options. Can someone show me how to do 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

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by stingman · Sep 09, 2012 at 09:13 PM

Create a new camera. When you click your 3D Text to select one of your menu options Enable the Camera you want enabled and disable the other.

NGUI is a game user interface designed by tasharen entertainment. it's a plugin I use for creating GUIs. You can buy it on the asset store, or you can create your own GUI setup. Regardless, since you don't have NGUI you need to write your own code to handle turning the camera on and off. for example... if using a mouse and considering you are writing in C#:

 using UnityEngine;
 using System.Collections;
 
 public class CameraChange : MonoBehaviour {
 
     public Camera camera1;
     public Camera camera2;
     RaycastHit hit;
     public GameObject text3D; // this is your 3d text object to click to turn off one camera and turn on the other.  Make sure it has a collider on it.
     
     void Start() {
     camera1.enabled = true;
     camera2.enabled = false;
     }
     
     void Update() {
     
     
         if (Input.GetMouseButtonDown(0))
                 {
                     Ray ray = Camera.mainCamera.ScreenPointToRay(Input.mousePosition);
                     if (Physics.Raycast(ray, out hit))
                     {
     
     if (hit.collider.gameObject == text3D) {
     camera1.enabled = false;
     camera2.enabled = true;
     }
     }
     }
     }
 }
Comment
Add comment · Show 9 · 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 Blink · Sep 10, 2012 at 04:01 PM 0
Share

I get an error saying unexpected token: Camera. I tried changing the script to

var Camera1 : GameObject;

var Camera2 : GameObject;

 void OnClick() { // OnClick is representative of whatever code you create to handle your click

 Camera.mainCamera.enabled = false;

 Camera2.enabled = true;

 }

but I got the error insert semicolon on line 4. Can you please help?

avatar image stingman · Sep 11, 2012 at 01:48 AM 0
Share

Sure thing, but do you even have NGUI? OnClick is a function provided in NGUI. Hence the reason I said that my example shows code from NGUI. Also, you are mixing javascript and C#. Another problem here. I wrote my example in C#. It should be pretty self explanatory but all you do is "enable" one camera and "disable" the other one. I suggest reading the Unity documentation a bit if you don't understand how the pseudo code I wrote for you works. It will only help you more in the long run. But the problem with my script above is that the variable camera2 is lowercase in the declaration and upper case in the function so I edited my post above to correct this. $$anonymous$$y bad :)

avatar image MickM · Sep 11, 2012 at 01:55 AM 0
Share

I am doing something similar switching between a top down map view to a close up battle camera for an encounter but I am using

battleCam.gameObject.SetActiveRecursively(true);

highCam.gameObject.SetActiveRecursively(false);

Is enabled a better way to do it than Set Active for any reason?

avatar image stingman · Sep 11, 2012 at 03:42 AM 0
Share

I don't know exactly how SetActiveRecursively cycles through game objects to deactivate/activate but I don't see the point in accessing all the other game objects/components if all you want to do is enable and disable one thing. If you can keep things simple why not? Unless it's more efficient for performance of course.

battleCam.enabled = true; highCam.enabled = false;

avatar image Blink · Sep 11, 2012 at 03:24 PM 0
Share

I understand the concept of enabling one camera and disabling the other but I dont know what NGUI actually is. Plus I have an error saying "A namespace can only contain types and namespace declarations" I'm confused, am I supposed to add to this script or something, please help?

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

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 Camera 3 Answers

Changing Target Depending On Car Selected 1 Answer

throwing a ball camera position changes 0 Answers

how would i create a button that animates the main camera when clicked? 1 Answer

camera switching 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