How I can add Achivements?

Can someone help me with achivements I need for 1 kill , 100 kills ,500 kills , 1000 kills , lose round , win round , win 100 round, win 1000 round, headshot 100, longshot 100 … like that ones…

1 Like

Sorry no idea on that. Might someone will help you. lol

That’s relative to how your project is setup. You need to give more details if you want people to help you.

There are some great tutorials out there about this. Try searching youtube or google.

1 Like

Thanks i know this yt video , and its complicated too much , my project is mp fps game and I want achivements for this tipe of game, i dont know :kill, headshot, longkill, win, lose, knife kill, with nightvision and something like that…

You have to track all those things. So each time a person does a kill, you record it. Then depending on when you award achievements, you need to check if they got enough headshots or whatever to get the achievement and award it at the correct time.

This isn’t just a simple thing that someone can give you. If you are using a backend service for accounts, check and see what sort of achievement system they have. Many provide ways to track achievements through them.

Otherwise, you’ll have to write your own, and a decent achievement system isn’t something that is easy to create. Looking at the video that @LiterallyJeff linked, there are 9 videos in that series, so I would say try to adapt it and ask questions along the way.

2 Likes

I tend to build a static StatsManager. (I know, static is evil, but statistics and achievements are truly global, meaning static is appropriate.) Then every time a thing happens in the game, it registers with the StatsManager. From there you can trigger achievements.

Sample code is as follows.

public static class StatsManager {

    static int noOfKills = 0;

    public static void SomethingDied (){
        noOfKills ++;
        CheckForAcheivements();
    }

    static void CheckForAcheivements(){
        if (noOfKills > 100) {
            // Do something amazing
        }
    }

}

public class Enemy : Monobehaviour {
    void OnDeath (){
        StatsManager.SomethingDied();
    }
}

In reality you can make this more complex to record whatever stats you are interested in.

1 Like

Thanks guys…:smile:

(

) I go to this video and use that script and I get error please help I dont know what I need to do

using UnityEngine;
using System.Collections;
using UnityEngine.UI;

public class AchievmentsManager : MonoBehaviour {

    public GameObject achievmentPrefab;

    public Sprite[] sprites;

    // Use this for initialization
    void Start ()
    {
        CreateAchievment("General","TestTitle","This is the description",10,0);   
    }
   
    // Update is called once per frame
    void Update () {
       
    }

    public void CreateAchievment(string category, string title, string description, int spriteIndex)
    {
        GameObject achievment = (GameObject)Instantiate(achievmentPrefab);

        SetAchievmentInfo(category, achievment, title, description, spriteIndex);
    }

    public void SetAchievmentInfo(string category, GameObject achievment, string title, string description, int spriteIndex)
    {
        achievment.transform.SetParent(GameObject.Find(category).transform);
        achievment.transform.localScale = new Vector3(1, 1, 1);
        achievment.transform.GetChild(0).GetComponent<Text>().text = title;
        achievment.transform.GetChild(1).GetComponent<Text>().text = description;
        achievment.transform.GetChild(2).GetComponent<Image>().sprite = sprites[spriteIndex];
    }
}

Bug is on 14 line?

I’m glad you told us what line the error is on, but also copy the error and paste it here.

You have 3 strings and 2 ints being passed as parameters when it is expecting 3 strings and 1 int.

Look I dont know what I need to do please help me, I not paste here script to tell you where is error, I paste script because I dont know how to fix it.

This is what you’re doing.

3196678--244214--giphy.gif

Your method takes 4 parameters, and you’re trying to fit in 5.

You’re saying you want to build a MP FPS, but you have issues fixing this error. I think that fixing your script for you will only encourage you to come to the forums to get scripts done, rather than figuring out basic shit by yourself, and given the scope of what you want to build, you’ll be coming here a lot.

You should take a look at this

Well, @Malleck666 told you what was wrong, but honestly, if you post a script and just say, hey, it has an error on this line, we can’t help you without knowing what the error is. So if you encounter an error you need to show the script, paste the error from Unity’s console and if able, tell us the line.

You have to help us help you. Knowing the exact error you are getting helps us to avoid 20 questions and guesses as to what is wrong.

Imgur: The magic of the Internet ; Imgur: The magic of the Internet There is picture of console in Unity and pics in Visual Studio, thanks a lot my friends…

Both @Malleck666 and @ADNCG have told you what is wrong with the error. And, this is a simple straight forward error.

If you are planning to do something as grand as a MP FPS game, you may want to scale back and look at some tutorials. It’s not going to get easier from here if you aren’t familiar with how to call a method and pass parameters.

Ok thanks.
Please only this…

using UnityEngine;
using System.Collections;
using UnityEngine.UI;

public class AchievmentsManager : MonoBehaviour {

    public GameObject achievmentPrefab;

    public Sprite[] sprites;

    // Use this for initialization
    void Start ()
    {
        CreateAchievment("General","TestTitle","This is the description",10,0); 
    }
 
    // Update is called once per frame
    void Update () {
     
    }

    public void CreateAchievment(string category, string title, string description, int points, int spriteIndex)
    {
        GameObject achievment = (GameObject)Instantiate(achievmentPrefab);

        SetAchievmentInfo(category, achievment, title, description, points, spriteIndex);
    }

    public void SetAchievmentInfo(string category, GameObject achievment, string title, string description, int points, int spriteIndex)
    {
        achievment.transform.SetParent(GameObject.Find(category).transform);
        achievment.transform.localScale = new Vector3(1, 1, 1);
        achievment.transform.GetChild(0).GetComponent<Text>().text = title;
        achievment.transform.GetChild(1).GetComponent<Text>().text = description;
        achievment.transform.GetChild(2).GetComponent<Text>().text = points.ToString();
        achievment.transform.GetChild(3).GetComponent<Image>().sprite = sprites[spriteIndex];
    }
}

This is script with points in achievment, but I dont need points ok?(This script work)I whant to delete points … please make script without points only Title , Description, Sprites. No points…

Please, PLEASE. Come on now, you didnt even try:

public void CreateAchievment(string category, string title, string description, int spriteIndex)
{
    GameObject achievment = (GameObject)Instantiate(achievmentPrefab);
    SetAchievmentInfo(category, achievment, title, description, spriteIndex);
}
public void SetAchievmentInfo(string category, GameObject achievment, string title, string description, int spriteIndex)
{
    achievment.transform.SetParent(GameObject.Find(category).transform);
    achievment.transform.localScale = new Vector3(1, 1, 1);
    achievment.transform.GetChild(0).GetComponent<Text>().text = title;
    achievment.transform.GetChild(1).GetComponent<Text>().text = description;
    achievment.transform.GetChild(3).GetComponent<Image>().sprite = sprites[spriteIndex];
}

There is error and I try it and it doesnt work ok?