#score
1 messages · Page 1 of 1 (latest)
Use ``` at start and the end of code
public Text Myscoretext;
private int ScoreNum;
// Start is called before the first frame update
void Start()
{
ScoreNum = 0;
Myscoretext.text = "Score : " + ScoreNum;
}
private void OnTriggerEnter2D(Collider2D Asteroid)
{
if (Asteroid.tag == "Asteroid")
{
ScoreNum = + 1;
Destroy(Asteroid.gameObject);
}
}
void Update()
{
Myscoretext.text = "Score: " + ScoreNum;
Debug.Log(ScoreNum);
}
yeah i did that
no =+ was me attempting to rewrite it
why are you rewriting instead of copy pasting..
i did += originally
now you're wasting time presenting issues that aren't even there
copy paste your exact code
public Text Myscoretext;
private int ScoreNum;
// Start is called before the first frame update
void Start()
{
ScoreNum = 0;
Myscoretext.text = "Score : " + ScoreNum;
}
private void OnTriggerEnter2D(Collider2D Asteroid)
{
if (Asteroid.tag == "Asteroid")
{
ScoreNum += 1;
Destroy(Asteroid.gameObject);
}
}
void Update()
{
Myscoretext.text = "Score: " + ScoreNum;
Debug.Log(ScoreNum);
}
there
exact code
when does it reset to 0?
after it goes to 1 it immedietly resets
do you assign to ScoreNum anywhere else?
no
how do you know it's resetting? the Debug.Log says 0?
yes as well as i have score: on the screen
do you have any errors in your console?
The code looks fine
yeah there's 1 error but i don't think it's causing the problem
show the error
cause it's just a clone being delted
Famous last words
Just show it
Oh, you're trying to destroy a prefab, rather than an instance of a prefab
that's you trying to delete an asset instead of a clone of a prefab
yeah how do i delete the clone
could it be the cause?
What are you trying to delete tho?
Is the prefab the asteroid or I am dumb and not able to understand the error
no u are right
the prefab is the asteroid
Then the asteroid is not getting deleted
And the code says if its destroyed only then the score can be 1
That's the problem
Is it actually an error related to this script?
Because you're destroying the thing that enters a trigger, but that should be an instance of a prefab
He is saying the asteroid is the prefab and it's getting destroyed in this script so I would assume so
But he has no reference to the prefab in this class
well a clone of the prefab
Yea you are also right
Exactly, so is this is the script the error is warning about?
yeah now i am asking how do i delete the clone?
yes
this is going off of my question tho
You are meant to give reference of the clone not the prefab
Nvm you didnt even give reference to the prefab
I see no issue with your code that would cause it to change from 0 to 1 back to 0, and since you won't provide any other information I cannot help you, good day
Heaven forbid we try and go onto a different but related issue
sorry
@pearl relic offtopic but I really want to say thanks to you
I am really sorry
When I was a beginner at my old I'd you were the one always helping me@pearl relic
And now I am here helping others I really want to say thanks to you
We haven't seen any spawning script, we haven't even got this class as a full script
So really, we're at a loss here
I am on a small amount of sleep and I am not properly thinking sorry.
i can give you the spawning script
if you want
Aye wheel it out then
@molten estuary also can you send the object hierarchy
{
public Transform asteroidPoint;
public GameObject asteroidPrefab;
void Start()
{
StartCoroutine("Reset");
}
void Update()
{
}
IEnumerator Reset()
{
GameObject asteroid = Instantiate(asteroidPrefab, new Vector2(Random.Range(-5f, 5f), 4f), asteroidPoint.rotation);
//yield on a new YieldInstruction that waits for 0.1 seconds.
yield return new WaitForSeconds(Random.Range(0.5f, 1f));
Destroy(asteroidPrefab);
StartCoroutine("Reset");
}
}```
spawning script
See
trying a new deltion
This is the script the error is for
i think i may have figured out how to delete it maybe
Bingo
Its clearly written in code
yeah now i see the issue
Well now that is out of the way, back to your 0s and 1s
Are there multiple instances of the score script in the scene?
@molten estuary can you send the object hierarchy once
Also, do we know for sure that the OnTriggerEnter2D and the subsequent if statement are both run?
sorry my bad i was on a thinking spree
ahh
i got it
the bullet is being cloned
and so all of them are resetting it
oh my god
I am just being an idiot sorry
No probs lmao