Unity Ninja Unity 3D Forum
To have exclusive access to all downloads, recourses and links within this forum, a free registered account is required. Just a heads up Wink

You are not connected. Please login or register

Unity Ninja Unity 3D Forum » HELP » Help (General) » I need help with achievments!

I need help with achievments!

View previous topic View next topic Go down  Message [Page 1 of 1]

1 I need help with achievments! on Wed Aug 30, 2017 4:07 am

Aleksandar


Member [Lv. 0]
Member [Lv. 0]
I go to this yt video and I use script from this video
This is script
Code:
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
using System.Collections.Generic;
 
public class AchievmentManager : MonoBehaviour
{
 
    public GameObject achievmentPrefab;
 
    public Sprite[] sprites;
   
   private AchievmentButton activeButton;
   
   public ScrollRect scrollRect;
   
   public GameObject achievmentMenu;
   
   public GameObject visualAchievment;
   
   public Dictionary<string, Achievment> acievments = new Dictionary<string, Achievment>();
 
    // Use this for initialization
    void Start ()
    {
      activeButton = GameObject.Finde("GeneralBtn").GetComponent<AchievmentButton>();
        CreateAchievment("General","Press W","TPress W to unlock this achievment",10,0);

      
      foreach (GameObject achievmentList in GameObject.FindGameObjectWithTags("AchievmentList"));
      {
         achievmentList.SetActive(false);
      }
      
      activeButton.Click();
      
      achievmentMenu.SetActive(false);
    }
 
    // Update is called once per frame
    void Update ()
   {
      if (Input.GetKeyDown(KeyCode.I))
     {
        achievmentMenu.SetActive(!achievmentMenu.activeSelf);
     }
     if (Input.GetKeyDown(KeyCode.W))
     {
        EarnAchievment("Press W");
     }
    }
   
   public void EarnAchievment(string title)
   {
      if (achievments[title].EarnAchievment())
      {
         GameObject achievment = (GameObject)Instantiate(visualAchievment);
         SetAchievmentInfo("EarnCanvas", achievment, title);
         StartCoroutine(HideAchievment(achievment));
      }
   }
   
   public IEnumerator HideAchievment(GameObject achievment)
   {
      yield return new WaitForSeconds(3);
      Destroy(achievment);
   }
 
    public void CreateAchievment(string parent, string title, string description,int points, int spriteIndex)
    {
        GameObject achievment = (GameObject)Instantiate(achievmentPrefab);
      
      Achievment newAchievment = new Achievment(name,description,points,spriteIndex,achievment);
      
      achievments.Add(title,newAchievment);
 
        SetAchievmentInfo(parent,achievment,title);
    }
 
    public void SetAchievmentInfo(string parent, GameObject achievment, string title)
    {
        achievment.transform.SetParent(GameObject.Find(parent).transform);
        achievment.transform.localScale = new Vector3(1, 1, 1);
        achievment.transform.GetChild(0).GetComponent<Text>().text = title;
        achievment.transform.GetChild(1).GetComponent<Text>().text = achievments[title].Description;
      achievment.transform.GetChild(2).GetComponent<Text>().text = achievments[title].Points.ToString();
        achievment.transform.GetChild(3).GetComponent<Image>().sprite = sprites[achievments[title].SpriteIndex];
    }
   
   public void ChangeCategory(GameObject button)
   {
      AchievmentButton achievmentButton = button.GetComponent<AchievmentButton>();
      
      scrollRect.content = achievmentButton.achievmentList.GetComponent<RectTransform>();
      
      achievment.Button.Click();
      activeButton.Click();
      activeButton = achievmentButton;
   }
}

I try to change this script, but i always make a mistake please help
I want to delete points in this script and I want to delete two achievment buttons from video I try to delete it and I always make mistake please help and this is script when I try to delete points and buttons...

Code:
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
using System.Collections.Generic;
 
public class AchievmentManager : MonoBehaviour
{
    public GameObject achievmentPrefab;
 
    public Sprite[] sprites;
   
   public GameObject visualAchievment;
   
   public Dictionary<string, Achievment> acievments = new Dictionary<string, Achievment>();
 
    // Use this for initialization
    void Start ()
    {
        CreateAchievment("General","Press W","TPress W to unlock this achievment",0);
    }
 
    // Update is called once per frame
    void Update ()
   {
     if (Input.GetKeyDown(KeyCode.W))
     {
        EarnAchievment("Press W");
     }
    }
   
   public void EarnAchievment(string title)
   {
      if (achievments[title].EarnAchievment())
      {
         GameObject achievment = (GameObject)Instantiate(visualAchievment);
         SetAchievmentInfo("EarnCanvas", achievment, title);
         StartCoroutine(HideAchievment(achievment));
      }
   }
   
   public IEnumerator HideAchievment(GameObject achievment)
   {
      yield return new WaitForSeconds(3);
      Destroy(achievment);
   }
 
    public void CreateAchievment(string parent, string title, string description, int spriteIndex)
    {
        GameObject achievment = (GameObject)Instantiate(achievmentPrefab);
      
      Achievment newAchievment = new Achievment(name,description,spriteIndex,achievment);
      
      achievments.Add(title,newAchievment);
 
        SetAchievmentInfo(parent,achievment,title);
    }
 
    public void SetAchievmentInfo(string parent, GameObject achievment, string title)
    {
        achievment.transform.SetParent(GameObject.Find(parent).transform);
        achievment.transform.localScale = new Vector3(1, 1, 1);
        achievment.transform.GetChild(0).GetComponent<Text>().text = title;
        achievment.transform.GetChild(1).GetComponent<Text>().text = achievments[title].Description;
        achievment.transform.GetChild(3).GetComponent<Image>().sprite = sprites[achievments[title].SpriteIndex];
    }
}

View user profile

View previous topic View next topic Back to top  Message [Page 1 of 1]

Permissions in this forum:
You cannot reply to topics in this forum