I want to interact with citizen while player Collider stays on citizen trigger by pressing X key. But the problem is i need to press and hold direction key to get input from key ‘X’.
This is my code:
void OnTriggerStay2D(Collider2D other)
{
relativePosition = transform.InverseTransformPoint(other.transform.position);
if (Input.GetKeyDown(KeyCode.X)){
Debug.Log(Input.GetKeyDown(KeyCode.X));
player.enabled = false ;
anim.enabled = false;
thisanim.enabled = false;
audio.GetComponent<AudioSource>().enabled = true;
audio.Play();
Textbox.SetActive(true);
text.GetComponent<Text> ().enabled = true;
if(textfile!= null){
textlines=(textfile.text.Split('
'));
}
if(endline==0){
endline = textlines.Length - 1;
}
if(relativePosition.x > 0.5)
{
Debug.Log("The object is to the right");
GetComponent<SpriteRenderer>().sprite=spr;
}
else if (relativePosition.x < -0.5)
{
Debug.Log("The object is to the left");
GetComponent<SpriteRenderer>().sprite=spl;
}
if(relativePosition.y > 0.5)
{
Debug.Log("The object is to the above");
GetComponent<SpriteRenderer>().sprite=spu;
}
else if (relativePosition.y < -0.5)
{
Debug.Log("The object is to the below");
GetComponent<SpriteRenderer>().sprite=spd;
}
}
}