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 Ereesden · Apr 09, 2011 at 04:22 AM · cameravariableswitchassign

Can't assign camera to variable.

I have three cameras in my scene. One follows the body of the tank, one follows the turret of the tank (rotation), and eventually, i want one that is a "zoomed-in" view. However, when I go to drag my cameras into the "camera1""camera2" variable slots in the inspector, I just simply cant. No errors or anything, it's just physically impossible to drag it onto the slot.

Here's a screenshot. You can see my code, and variables on the right, and my cameras on the left.

alt text

Here's the code I'm using, and I've seen it a hundred times.

var camera1 : Camera; var camera2 : Camera;

function Start () { camera1.enabled = true; camera2.enabled = false; }

function Update () { if (Input.GetKeyDown ("2")){ camera1.enabled = false; camera2.enabled = true; } if (Input.GetKeyDown ("1")){ camera1.enabled = true; camera2.enabled = false; }
}

Comment
Add comment · Show 3
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 cidmodder · Apr 09, 2011 at 04:46 AM 1
Share

have you put the script on something? I can't attach cameras to the script until I've actually put it on something.

avatar image Ereesden · Apr 09, 2011 at 04:58 AM 0
Share

You nailed it man. Thank you!

avatar image TheDemiurge · Apr 09, 2011 at 07:46 AM 0
Share

If you can, post an answer (not a comment) stating the solution and mark it as accepted. It takes it off the "unanswered" list.

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by DaveA · Apr 09, 2011 at 04:46 AM

When you drag objects like that, it's gonna be Transform (or maybe GameObject?). Anyway, try Transform and then GetComponent(Camera) on them.

Comment
Add comment · Show 2 · 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 Ereesden · Apr 09, 2011 at 04:58 AM 0
Share

Thanks, but it was a simple, dumb mistake. I hadn't attached the script!

avatar image TortoRacoon Ereesden · Apr 30, 2019 at 05:23 AM 0
Share

It would be very helpfull if you explained that "Attaching the script", I'm having the exact same problem, except that I have other objects successfully assigned to the script, is only the fkn camera that is not assigning for some reason

avatar image
0

Answer by In0sc0p3dJFK · May 13, 2021 at 02:40 AM

@TortoRacoon make sure your camera is a prefab as well as the object you're trying to assign it to

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

2 People are following this question.

avatar image avatar image

Related Questions

Main Camera Switch? 3 Answers

changing player (getting in vehicles) 3 Answers

camera switch not working 3 Answers

Single Camera Lerping between three characters? (code provided) 0 Answers

Changing variable numbers depending on current player model. 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