• 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 MIKI PR · Nov 22, 2014 at 04:48 PM · cameratransformmovehow-to

How to move the camera depending on the score?

Thanks for reading my question...

First i am very new to scripting , i have been days reading how to move the camara how i want but nothing works exactly.

I want to move the camara position Y (9) each time the score of the game reach 7 or a multiple of seven

Example:

      Score = 7  Move Camraa in Y 9
      Score = 14 Move Camara in Y 9 more
      Score = 21 Move Camara in Y 9 more
      And so.....

The script i have, the camara move Y wen the score reach 7 but never stops , it continuously moving in Y.

Here is the script , thanks for your help.

 #pragma strict
 var guiHeight : GUIText; 
 var myCamera : GameObject;
 var sum : int = 2;
 
 private var height: int = 0 ;  
 
 function Start () {
  guiHeight.text = "Height: 0"; 
 }
 
 function Update () {
 
 
  if(Input.GetButtonDown("Fire1")){ 
   height += 1;
   guiHeight.text = "Height: " + height;   
  }
    if( height % 700 == 7 )
           {
             myCamera.transform.position.y += 9; 
           }
 }

 
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 RadioactiveTechnologies · Nov 22, 2014 at 04:58 PM

You can use this, and if you werent starting at a height of zero, just add what you're starting at to the transform changing at the end.

  #pragma strict
  var guiHeight : GUIText; 
  var myCamera : GameObject;
  var sum : int = 2;
  
  private var height: int = 0 ;  
  
  function Start () {
   guiHeight.text = "Height: 0"; 
  }
  
  function Update () {
  
  
      if(Input.GetButtonDown("Fire1")){ 
          height += 1;
         guiHeight.text = "Height: " + height;   
      }
      if( height%7 == 0 )
           {
               myCamera.transform.position.y = height*9; 
           }
      }
 }

Please upvote this answer if it was helpful!

Comment
Add comment · Show 4 · 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 MIKI PR · Nov 22, 2014 at 06:21 PM 0
Share

WoW!!!! you are the best!!!!

Well Got 2 Bugs but fix it.

  if( height%7 == 0 )
            {
                myCamera.transform.position.y = height*9; 
            }

Bugs

  1. $$anonymous$$y camara starting position is Y (2) , but wen i hit play it get down to (-1) (I think this is what you mean)

2.Wen Score get to 7 the camara went up to Y (62) , then wen the score get 14 the camara move to Y (125)

Solution

I Change height*9 to height+3

Bug Script myCamera.transform.position.y = height*9;

Fix Script myCamera.transform.position.y = height+3;

avatar image RadioactiveTechnologies · Nov 22, 2014 at 06:33 PM 0
Share

try using

 myCamera.transform.position.y = height/7*9+2;

I forgot to make it divide by 7. That's important.

avatar image MIKI PR · Nov 22, 2014 at 07:06 PM 0
Share

okok , thanks you save me XD

avatar image RadioactiveTechnologies · Nov 23, 2014 at 04:54 AM 0
Share

No problems. Have a good day!

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.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Can you help me understand this Camera calibration between Kinect and PS Move? 2 Answers

Scale guiTexture with respect to camera distance 1 Answer

What is the best way to deal diferent resolutions and gameobject sizes? 0 Answers

Object jitters when camera is moving and is in the near? 0 Answers

Finding the limits of transform coordinates 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