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 Given · Nov 06, 2010 at 08:54 PM · cameraloadleveland-operator

2 questions: camera change and a question about using &&

Does anyone have a script that would allow me to change cameras? If not, could someone point me to a tutorial or something? Thanks. Now for the real question: I have a game where you are flying in a spaceship and when you fly too close to a planet it loads a level (namely the planet level). I used the AND operator for this: Code:

if ( transform.position.z >= 6088.709 && transform.position.z <= -5826.924
     && transform.position.x >= -5928.328 && transform.position.x <= 5926.727)
     && transform.position.y <= 5954.533 && transform.position.y >= -7152.666 )
{
   Application.LoadLevel(1);
}

Translation: if the player's position is between z 6088.709 and -5826.924, x -5928.328 and 5926.727 and y 5954.533 and -7152.666, it loads level (1)

This method is clearly not working ( it gives the error "unknown identifier: &&" )

Is there a better way of doing this?

Comment
Add comment · Show 1
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 LeiterJakab · Nov 06, 2010 at 09:02 PM 0
Share

You have 2 closing parentheses after the if statement. transform.position.x <= 5926.727)

2 Replies

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

Answer by Jesse Anders · Nov 06, 2010 at 09:00 PM

It looks like you have an errant ')' in your conditional; that's probably what's causing the error to be generated.

As for better ways of doing it, a couple of alternatives would be to use a trigger, or to use the Bounds struct and the function Bounds.Contains().

Comment
Add comment · Show 1 · 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 Given · Nov 06, 2010 at 11:59 PM 0
Share

Well that stopped the error... Its not doing what I wanted it to do still.

avatar image
1

Answer by · Nov 07, 2010 at 04:37 AM

In addition to the errant ')', you've confused your <= and >= ... I formatted your code to make it easier to see.

if ( transform.position.z >= 6088.709 && transform.position.z <= -5826.924
// if  z is greater than 6088 and less than -5826
     && transform.position.x >= -5928.328 && transform.position.x <= 5926.727
// and x is greater than -5928 and less than 5926
     && transform.position.y <= 5954.533 && transform.position.y >= -7152.666 )
// and y is less than 5954 and greater than -7152
{
   Application.LoadLevel(1);
}

You need to flip the checks on 'z', and it should work. It'd be easier to spot this kind of error if you did your checks in the same order. i.e. "if x is greater than 1 and less than 2" and stuck to that format for y and z.

However, as Jesse said, there are better ways to implement this functionality, but this will fix your problem in the interim.

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

No one has followed this question yet.

Related Questions

Why my Camera is getting Duplicated? 0 Answers

How to make camera position relative to a specific target. 1 Answer

Continue playing sound effect on camera after LoadScene 1 Answer

Losing reference to the camera after loading new scene 0 Answers

Get new Camera after Application.loadLevel 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