Hello, I am trying to replicate a code in a script I made following a tutorial, I thought I could just use what I learned in the previous tutorial, which was a code to save text inputted in a field, to make a code for naming saves from a separate inputfield.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class SaveControl : MonoBehaviour
{
public string theText;
public string theName;
public GameObject ourNote;
public GameObject namePlaceHolder;
public GameObject placeHolder;
public GameObject saveAnim;
public string customName;
void Start()
{
theText = PlayerPrefs.GetString("NoteContents");
placeHolder.GetComponent<InputField>().text = theText;
namePlaceHolder.GetComponent<InputField>().text = theText;
string customName = theName;
}
public void SaveNote()
{
theText = ourNote.GetComponent<Text>().text;
customName = theName.Getcomponent<Text>().text;
PlayerPrefs.SetString("NoteContents", theText);
PlayerPrefs.SetString("theName", customName);
StartCoroutine(SaveTextRoll());
}
IEnumerator SaveTextRoll(){
saveAnim.GetComponent<Animator>().Play("SavedAnim");
yield return new WaitForSeconds(1);
saveAnim.GetComponent<Animator>().Play("New State");
}
}
I keep getting an error at line 28, string does not contain definition for GetComponent. What am I doing wrong?
Also, I imagine the code I’m trying to make here doesn’t work for multiple saves. Is there a line I could insert to make it save a separate save file every time?
Thanks