Skip to main content

Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
TagsGame Engines

You're fine, don't worry!

Ok, let's start with this: what version of Unity are you using?
Also, how to you picture your scoring system functioning - as in, what actions do you intend to have increase your score and by how much?

2019.4 11f1, and i want it so everytime you kill a red it goes up by 1, green goes up by 4, and black (in hard mode) goes up by 8

 

Without having access to your code, I can only speak in generalities.
Basically, you should have a score object for which you create a function that increments the score by a given amount:

Example:

private int score = 0;
public void IncreaseScore(int points)
{
    score += points
    //here you should call code to update your HUD's score display
}

Now every time you kill an object, you should call the Score Object's "IncreaseScore" and pass it the correct number of points before destroying your enemy object.

So, for example, your red object would call the function by passing the amount of 1: IncreaseScore(1) and black would call the function by passing the amount of 8: IncreaseScore(8).

As to how *specifically* you call the score object's IncreaseScore function from your enemy depends on how you implemented it. And to know that, I'd need to see your code. If you'd like, you can send me the project files (or upload them to itch and send me a link to them) here: game.professor@yandex.com

So, to summarize, i make a empty game object called score and i create a function that adds a certain number for when a the enemy is destroyed?

Also, How would i make an if statement to check if my enemy gameobject is destroyed?

Usually destroying an object will set it to "null", so you can just check if the object is "null":

if (Enemy == null)

OH. MY. GOD. Thank you so much i needed that one line for like forever. now i can probably even make a level system!

Thaeres one problem tho, I did the code correctly, but it isnt working for the score count! heres my code:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class Score : MonoBehaviour
{
    public Text scoreDisplay;
    public int score = 0;
    public Enemy Enemy;
    // Update is called once per frame
    void Update()
    {
        scoreDisplay.text = "SCORE:" + score;
    }
    public void IncreaseScore()
    {
        if(Enemy == null) ;
        {
            score += 1;
        }
    }
}

Hmm, what is calling the function "IncreaseScore"? Is this script attached to an enemy that has a call to it on its death?

wELP Im stupid.

NO! You are NOT stupid.

This is an extremely common mistake. It's one you will probably make at least once on every project (multiple times for larger projects). Everyone does. It's one of many simple errors you learn to look for first so you can fix it before tweaking your code.

If you only take one thing from this experience, I want it to be learning to not get down on yourself for making simple errors and mistakes; they aren't character flaws, they're just a part of the task. NO ONE writes perfect code the first time, every coder uses a debugger.