I’m new to coding in Unity and I’ve found this code that I wanted to use for my game but it states that “The name ctrl does not exist in the current context”. How can I fix this?
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PickUp : MonoBehaviour
{
private bool _isPickedUp = false;
void Update()
{
if (Input.GetKeyDown(KeyCode.LeftControl))
{
ctrl = true;
}
else if (Input.GetKeyUp(KeyCode.LeftControl))
{
ctrl = false;
if (_isPickedUp)
{
transform.SetParent(null);
_isPickedUp = false;
}
}
}
private void OnCollisionStay2D(Collision2D collision)
{
if (ctrl && !_isPickedUp && collision.gameObject.tag == "Player")
{
transform.SetParent(collision.transform, true);
_isPickedUp = true;
}
}
}