error CS1061: Type `object' does not contain a definition for `GetComponent' and no extension method `GetComponent' of type `object' could be found. Are you missing an assembly reference
I'm adding achievements to my game and visual studio is giving me errors: using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI;
public class Achievement01 : MonoBehaviour { // Start is called before the first frame update public GameObject achNote; public AudioSource achSound; public bool achActive = false;
// Update is called once per frame
public GameObject ach01Image;
public static int ach01Count;
public int ach01Trigger = 5;
public int ach01Code;
void Update()
{
if (ach01Count == ach01Trigger && ach01Code != 12345)
{
string Trigger01ach = null;
StartCoroutine(Trigger01ach());
}
}
IEnumerator Trigge01Ach()
{
achActive = true;
ach01Code = 12345;
PlayerPrefs.SetInt("Ach01", ach01Code);
achSound.Play();
ach01Image.SetActive(true);
achTitle.GetComponent<Text>().text = "Achievement Unlocked!";
achDesc.GetComponent<Text>().text = "What Is This Place?";
achNote.SetActive(true);
yield return new WaitForSeconds(7);
achTitle.GetComponent<Text>().text = "";
achDesc.GetComponent<Text>().text = "";
achNote.SetActive(false);
}
}
Am I missing something ot the language needs to be upgraded. TBH i dont like visual Studio. I always use MonoDevelop (I know its deprecated).
Answer by Bunny83 · Jan 16, 2019 at 03:15 AM
You haven't declared / defined any variable called "achTitle". At least i can't see one even though you did not properly mark your code as code. The same holds true for "achDesc". You probably wanted to declare them as GameObject variables of your class. Though it would make more sense to declare them directly as "Text" and assign the proper gameobject to those variables. That way you don't need to use GetComponent at all.
Your answer
Follow this Question
Related Questions
.sln file in latest version of Unity3D 2018 3 Answers
No Monobehaviour scripts in the file 0 Answers
[SOLVED] How to Store Object Player Entered Trigger of? 1 Answer
Nope: frist time opened unity and this error massage keep showing hlep! 1 Answer
How to Disconnect a client from the server properly using unity Netcode for GameObjects ? 0 Answers