- Home /
How to use multiple keys to get the same outcome?
Hi all, I need to know how I can get the WASD keys (pressed separately to activate 2 gameobjects). For example, when W is pressed complete the activation of gameobjects. When A is pressed activate them again. (not all at the same time)
All I can find and do is get when 1 key is pressed or when multiple keys are pressed at the same time. This is not what I want.
Here is my script so far:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class WASDAnim : MonoBehaviour
{
public GameObject IdleAnimation;
public GameObject RunAnimation;
void Update()
{
if (Input.GetKey(KeyCode.W))
{
IdleAnimation.SetActive(false);
RunAnimation.SetActive(true);
}
else
{
IdleAnimation.SetActive(true);
RunAnimation.SetActive(false);
}
}
}
Any help would be highly appreciated!
Answer by PersianKiller · Sep 16, 2017 at 01:39 PM
you can use this
if (Input.GetKey(KeyCode.W) ||Input.GetKey(KeyCode.S) || whateveryou want xD)
{
IdleAnimation.SetActive(false);
RunAnimation.SetActive(true);
}
I don't know that's a 2d game or not,you better to use Input.GetAxisRaw,so you can assign a lot of keys easily.
Thanks a ton for your help! This script works really well.
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
How to create a secure package? 0 Answers
HOW i SOLVE ROOT MOTION PROBLEM WITH ANIMATIONS MADE IN UNITY 0 Answers