I’m writing script which sets a condition to enable GetKeyDown. The condition is that the player needs to collide with a particular Game Object, and once they have done that then they will be able to press the spacebar to make an image appear. Prior to this I wrote a script which made the image appear as soon as the player collided with a Game Object which worked perfectly but now that I’ve added GetKeyDown into the mix it hasn’t worked.
The error message ‘Input.GetKeyDown(KeyCode)’ is a method, which is not valid in the given context’ also appeared.
I’ve inserted the code below. Thanks in advance!
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class ArtworkAppear : MonoBehaviour
// This script sets a condition which only allows GetKeyDown("space") once they have collided with another game object
{ [SerializeField] private Image customImage;
// Player needs to 'collect' item to enable interacting with a different game object
void OnTriggerEnter (Collider other)
{
//If player collides with the item (collects it) interaction with another game object is enabled
if (other.CompareTag ("Player"))
{
Input.GetKeyDown.enabled=true; //Now that the player has collided with the game object 'GetKeyDown' is enabled for the next interaction
}
if (Input.GetKeyDown("space")) //Now that GetKeyDown is enabled, once pressed a custom image appears
{
customImage.enabled = true;
}
}
}