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 Babilinski · May 07, 2011 at 08:27 PM · camerabuttoncamera-movementarrow-keys

Camera with arrow keys?

I want my camera only to move then I hit my arrow keys. can anyone help? This script only dose it with a mouse

using UnityEngine; using System.Collections;</p> <p>public class camera : MonoBehaviour { public Transform target; public float walkDistance; public float runDistance; public float height; public float zoom; public float xSpeed = 250.0f; public float ySpeed = 120.0f;</p> <pre><code>private Transform _myTransform; private float x; private float y; private float BaseValue; //me // Use this for initialization void Start () { if(target == null) Debug.LogWarning("we have no tageet"); _myTransform = transform; } void LateUpdate() { if(Input.GetMouseButton(0)) { x += Input.GetAxis("Mouse X") * xSpeed * 0.02f; y -= Input.GetAxis("Mouse Y") * ySpeed * 0.02f; // y = ClampAngle(y, yMinLimit, yMaxLimit); Quaternion rotation = Quaternion.Euler(y, x, 0); Vector3 position = rotation * new Vector3(0.0f, 0.0f, -walkDistance) + target.position; _myTransform.rotation = rotation; _myTransform.position = position; } } </code></pre> <p>}

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 ina · May 07, 2011 at 08:38 PM

Simply replace Input.GetAxis with Input.GetKey

You would probably want to map the left arrow as a negative input, and down as negative input etc.

var factor = 0.02f; // change this depending on interval to move camera if(Input.GetKey(KeyCode.LeftArrow)) x -= xSpeed * factor; else if(Input.GetKey(KeyCode.RightArrow)) x += xSpeed * factor if(Input.GetKey(KeyCode.UpArrow)) y -= xSpeed * factor; else if(Input.GetKey(KeyCode.DownArrow)) y += xSpeed * factor

Comment
Add comment · Show 6 · 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 Babilinski · May 07, 2011 at 08:40 PM 0
Share

is this java? if yes what dose var mean?

avatar image ina · May 07, 2011 at 08:41 PM 0
Share

var declares a new variable.

avatar image Babilinski · May 07, 2011 at 08:52 PM 0
Share

ahh i know im asking a lot but could you put it int the script b/c im getting

error CS1502: The best overloaded method match for UnityEngine.Input.GetButtonDown(string)' has some invalid arguments error CS1503: Argument #1' cannot convert UnityEngine.$$anonymous$$eyCode' expression to type string'

avatar image ina · May 07, 2011 at 11:28 PM 0
Share

sorry, i typo'd keycode ins$$anonymous$$d of $$anonymous$$eyCode ... should work now if you replace the x and y axis getstuff with this

avatar image Babilinski · May 09, 2011 at 10:51 AM 0
Share

thank you for your 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

No one has followed this question yet.

Related Questions

Buttons move with the camera and I don't want that 0 Answers

Camera Reset Script 1 Answer

Why can't I change my camera's position? 2 Answers

Many cameras with Camera.main.ScreenToWorldPoint trouble. 2 Answers

ScreenToWorldPoint for different ortographic size 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