Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 /
  • Help Room /
avatar image
0
Question by SPOTNINJADUD7890 · Aug 20, 2016 at 09:44 AM · c#unity5unityeditor

How to i use get key to use the turn?

I need to make it so it only turns when i press x plz help.

 using UnityEngine;
 using System.Collections;
 
 public class Lerp180Left : MonoBehaviour
 {
     public Vector3 axis = new Vector3( 0, 1, 0 );
     public float degrees = 90f;
     public float timespan = 1f;
 
     private float _rotated = 0;
     private Vector3 _rotationVector;
 
     public void Start()
     {
         axis.Normalize();
         _rotationVector = axis * degrees;
     }
 
     public void Update()
     {
         _rotated += degrees * (Time.deltaTime / timespan);
         if ( degrees > _rotated )
             transform.Rotate( _rotationVector * (Time.deltaTime / timespan) );
     }
 
 }
 




Comment
Add comment · Show 4
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 sourav13 · Aug 20, 2016 at 10:43 AM 0
Share

Use Input.Get$$anonymous$$ey or GetButton something and than rotate , not sure if you have to put this line _rotated += degrees * (Time.deltaTime / timespan); as well in the if keypressed

avatar image SPOTNINJADUD7890 sourav13 · Aug 20, 2016 at 06:40 PM 0
Share

i know i need to do that i tried but i don't understand were to put the code.

avatar image shadowpuppet · Aug 20, 2016 at 07:27 PM 0
Share

in the update function I imagine add a key command if(Input.Get$$anonymous$$eyDown ($$anonymous$$eyCode.N)) {

avatar image SPOTNINJADUD7890 shadowpuppet · Aug 22, 2016 at 02:29 AM 0
Share

Already tried that dude sorry

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Jessespike · Aug 22, 2016 at 04:56 AM

 void Update() {
     if (Input.GetKey(KeyCode.X))
     {
         _rotated += degrees * (Time.deltaTime / timespan);
         if (degrees > _rotated)
             transform.Rotate(_rotationVector * (Time.deltaTime / timespan));
     }
 }

ScriptReference - Input

ScriptReference - Input.GetKey

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 SPOTNINJADUD7890 · Aug 22, 2016 at 11:38 AM 0
Share

sorry but this is not working either it make me hold down the key D:

avatar image sourav13 SPOTNINJADUD7890 · Aug 22, 2016 at 01:41 PM 0
Share

If you want to rotate completely to an extent once a key is pressed I would recommend the use of coroutine. Call it once with coroutine and and use boolean as well to not to calling it again and again , if the button is kept on as pressed

avatar image Jessespike SPOTNINJADUD7890 · Aug 22, 2016 at 03:54 PM 0
Share
 bool keyPressed = false;
 void Update() {
     if (Input.Get$$anonymous$$eyDown($$anonymous$$eyCode.X))
     {
         keyPressed = true;
     }

     if (keyPressed) 
     {
         _rotated += degrees * (Time.deltaTime / timespan);
         if (degrees > _rotated)
             transform.Rotate(_rotationVector * (Time.deltaTime / timespan));
     }
 }
avatar image SPOTNINJADUD7890 Jessespike · Aug 23, 2016 at 09:30 PM 0
Share

this works! but it only works once! i need it to be repeatable please.

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

7 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

EditorUtility.OpenFilePanel for UnityWebGL (Runtime) 1 Answer

Character Controller script cannot jump on top of platform because of slope limit being 45 1 Answer

Gizmos and Handles 1 Answer

unity3d 5 game on fullscreen shows only half of game screen 4 Answers

playing sound on certain condition on object 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