Note:My unity ver. is 2022.3.49f1
I have a script and it have a bug in 26,13 line.(i think it’s line.) the script:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class AchievementScript : MonoBehaviour
{
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
}
public GameObject Achievement;
public GameObject ScoreRequire;
public void Get()
{
if (ScoreRequire("string")) <---ERROR HERE
{
Achievement.SetActive(true);
}
}
}
Can you show the ScoreRequire
function?
You actually have a good representation of valuable lessons here. I’m not nitpicking I am pointing out how the tools, language and libraries work.
There is no mention of a text property or a text class what you posted. The error almost certainly cannot be at the point indicated. It can be part of a stack trace however. ScoreRequire is a GameObject you cannot use it like an object, it isn’t code. Maybe you have a class with the same name but it isn’t shown to exist. My guess is that you may have assigned a Text object to it in the Inspector.
“string” is almost certainly not the value you are planning on testing for.
I’ll suggest a bit more work with classes, methods and properties before you move on. A few things are essential to understand, datatypes for instance, null references. Make up simple examples that you can test by outputting Debug.Log lines.
A bit of time spent learning the fundamentals will save you hundreds of hours wondering why something (fairly obvious in most cases) isn’t working. Encounter the condition during your testing sessions rather than in your application.
Also keep the simple test project around so you can whip up additional tests in it that won’t affect your final project.
That’s not a bug, you’re just making typing mistakes.
Go back to the tutorial where you got this and fix what you’ve typed. There are at least two or three separate errors here and additionally as Tley points out, you have misrepresented what the error is.
I won’t confuse the issue by trying to guess what the original intent was.
Two steps to tutorials and / or example code:
1. do them perfectly, to the letter (zero typos, including punctuation and capitalization)
2. stop and understand each step to understand what is going on.
If you go past anything that you don’t understand, then you’re just mimicking what you saw without actually learning, essentially wasting your own time. It’s only two steps. Don’t skip either step.
Imphenzia: How Did I Learn To Make Games: