Multiple Key Press

Hello,

i m wanting t use multiple key press for same key. When i first key press , game object will turn 90 degree, for second click again it will turn 90 degree. i tried different solutions but could not reach a conclusion. Can you help me for solution?

Can you help me this about ?

  1. Code is useful, post the code that isn’t working the way you think it should
  2. Describe what you expect the code to do and what it actually does so we can help you figure out the problem.
  3. Most people on here will help with issue, but we also want those we help to learn and not just be given the answers.

Thanks for your answer and explains Demyze. So i know your says.
I could not multiple key press for same key, and have not got an idea how it writes, i wanted help for script sample, documents or link.
if somebody help me , i will glad

Sorry for my english :slight_smile:

Okay, before I help out with a script, I have some questions so I can help guide you to the answer you’re looking for.

Do you want the cube to rotate while the key is pressed and held down for example, if the key is pressed and held down the cube rotates x degrees every y seconds?

or

Do you want the cube to rotate if the key is pressed, then released, then pressed again for example key is pressed, cube rotates x degrees, key is released, key is pressed again and the cube rotates another x degrees?

I wrote a script that can do 2 things and you can pick the one you want. Attach this script to a game object like a cube and you’ll see how it works.

Press Comma and the cube will rotate 90 degrees in the Y axis per keypress.
Press Period and hold the key down and the cube will rotate 1 degree in the Y axis every update.

Keep in mind this is not the full answer. This will rotate a cube, but it will rotate based on the update call which is based on how fast someone’s computer is. The rotation should be based on the change in time since last call of update. You should be able to find the answer yourself, google or search the forum. I think you can find finish this script yourself. Also this is based on on ordered rotations… there are better ways to rotate object to prevent issues I’m sure you’ll come across. This script is just to get you started.

using UnityEngine;
using System.Collections;

public class test : MonoBehaviour {

	// Use this for initialization
	void Start () {
	
	}
	
	// Update is called once per frame
	void Update () {
		if (Input.GetKeyDown (KeyCode.Comma))
		{
			transform.Rotate(0,90,0, Space.Self);
		}
		if (Input.GetKey(KeyCode.Period))
		{
			transform.Rotate(0,1,0, Space.Self);
		}
		
	}
}

Thank you for helps

i want the cube to rotate if the key is pressed, then released, then pressed.

i m working on your script, ll tell last status