I have this code used to save input from a InputField. When I press the button that executes this script I get the error “Object reference not set to an instance of an object” at line 13. I have used a similar get input script in other parts of the project so I am not sure what the problem is here. The button is pressed after I enter my input into the input field.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class attackInputField : MonoBehaviour
{
public InputField WhoToAttack;
public static string victim="";
public void save()
{
victim = WhoToAttack.text;
Debug.Log("victim chosen");
PlayerPrefs.SetString("textTextKeyName", victim);
}
}