So I’ve been working on character movement for an isometric game, where I want the character to have an animation for moving 0 degrees, 45 degrees and 90 degrees. 0 and 90 have been working just fine, but I’ve have trouble with 45 as it requires two buttons to be pressed simultaneously, and I don’t know the code for adding button input together, nor can I find it. Help would be appreciated!
{
//I've tried using +
if (Input.GetKeyDown (KeyCode.W) + (KeyCode.D))
{
anim.SetInteger("State", 6);
}
//And I found && online,
if (Input.GetKeyUp (KeyCode.W) && (KeyCode.D))
{
anim.SetInteger("State", 0);
}
}
but both give me errors such as "Operator ‘+’ cannot be applied to operands ‘bool’ and ‘UniyEngine.KeyCode’
Again, help would be great. Thanks!
EDIT: Ok, the error was fixed but the particular animation won’t play. It’ll play the one for 90 degrees and 0 degrees, but no 45.
EDIT AGAIN: With help (thank you) I managed to get the animation to play when both buttons are pressed down, unfortunately there was a significant time delay between pressing the buttons and the animation playing, except for the “D” key. Any solutions?
using UnityEngine;
using System.Collections;
public class Player_Animator_Control : MonoBehaviour
{
Animator anim;
// Use this for initialization
void Start ()
{
anim = GetComponent<Animator> ();
}
// Update is called once per frame
void Update ()
{
{
// Seems in the new state both D and W are pressed
if (Input.GetKey(KeyCode.W) && Input.GetKey(KeyCode.D))
{
//Move at a 45 degree angle
anim.SetInteger ("State", 6);
}
// Seems in the new state W is pressed, D is not
else if (Input.GetKey(KeyCode.W) && !Input.GetKey(KeyCode.D))
{
//Move at a 90 degree angle
anim.SetInteger ("State", 7);
}
// Seems in the new state D is pressed, W is not
else if (!Input.GetKey(KeyCode.W) && Input.GetKey(KeyCode.D))
{
//Move at a 0 degree anle
anim.SetInteger ("State", 5);
}
// Neither pressed
else
{
anim.SetInteger ("State", 0);
}
}
}
}