I want to make an object with a Sprite Renderer invisible. When the player presses a key, the object would become visible. How would I do that?
Here is my code so far:
using UnityEngine;
public class A1 : MonoBehaviour {
// Use this for initialization
// Update is called once per frame
void Update()
{
if (Input.GetKey("a"))
{
gameObject.SetActive(value: false);
}
if (Input.GetKey("d"))
{
gameObject.SetActive(value: true);
}
}
}
GameObjects that are disabled do not get Unity methods called on them.
You need to either keep the GameObject active and disable/enable the sprite renderer or have another object receive the mouse input and control the first object’s activation state.
Here you go 
GetComponent<SpriteRenderer>().enabled = false;