Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
Tags
(1 edit) (+1)

Hello!

Your request is a little bit confusing, but what I understand is that you may  want to have a GameObject with a script with the score (number of enemies killed perhaps?), and what you want to have is a way to keep track of how many are getting killed in that gameobject.

You can try different approaches and tricks, like search for components, link gameobjects between them, events and delegates, playerprefs...

But maybe the easiest or faster to understand is using a Singleton for a GameManager script that will keep track of the score and other elements.

Here the Singleton code page:

http://wiki.unity3d.com/index.php/Singleton

You may need to create a gameobject with a Monobehaviour to act as the GameManager:

public class GameManager: Singleton<GameManager>
{
    ...
    public int PlayerKillCount;
    ...
}

And then, just before destroying the object in that other script you have, you make a call to this PlayerKillCount variable:

...
GameManager.Instance.PlayerKillCount += 1; 
Destroy(gameobject); 
...

The best approach depends of a lot of things to consider, but if you're just looking for a place to keep the score and be able to access to it easily by other scripts, this is a solution.

If you have further questions, just shoot.

Good luck!