Hi guys,
I have an issue with my achievement script in that it displays the gui as if an achievement has been awarded on game start… obviously something I dont want and is probably a typo or something where it shouldnt be!
using UnityEngine;
using System.Collections;
// Creditting help for this script from: http://forum.unity3d.com/threads/178594-Basic-ACHIEVEMENT-System-C-Please-Help
public class quick_info : MonoBehaviour
{
GUIStyle AchievementPanel = new GUIStyle();
public Texture ArtefactCollection;
public int display_time;
public float menu_x;
public float menu_x_target;
public bool moving_in;
public float time;
void Start()
{
moving_in = true;
menu_x_target = Screen.width - 305;
menu_x = Screen.width;;
SetupStyles();
}
void Update()
{
time += Time.deltaTime;
if (menu_x > menu_x_target moving_in)
{
menu_x -= Time.deltaTime * 400;
}
else if (menu_x < Screen.width time > display_time)
{
moving_in = false;
menu_x += Time.deltaTime * 400;
if (menu_x > Screen.width)
{
Destroy(GetComponent<quick_info>());
}
}
}
void SetupStyles()
{
AchievementPanel.normal.background = (Texture2D)Resources.Load("QuickTexture");
}
void OnGUI()
{
GUI.BeginGroup(new Rect(menu_x, 300, 300, 150), "", AchievementPanel);
GUI.EndGroup();
}
}
using UnityEngine;
using System.Collections;
public class AchievementManager : MonoBehaviour
{
public AudioClip AchievementSound;
public bool AchievementAccomplished;
public void OnAchievementWon(string WhatAchievement)
{
switch(WhatAchievement)
{
case "Achievement1":
AchievementAccomplished = true;
audio.PlayOneShot(AchievementSound);
quick_info a = gameObject.AddComponent<quick_info>();
a.display_time = 5;
break;
case "Achievement2":
AchievementAccomplished = true;
audio.PlayOneShot(AchievementSound);
quick_info b = gameObject.AddComponent<quick_info>();
b.display_time = 5;
break;
case "Achievement3":
AchievementAccomplished = true;
First_Step c = gameObject.AddComponent<First_Step>();
c.display_time = 5;
audio.PlayOneShot(AchievementSound);
break;
case "Achievement4":
AchievementAccomplished = true;
quick_info d = gameObject.AddComponent<quick_info>();
d.display_time = 5;
audio.PlayOneShot(AchievementSound);
break;
case "Achievement5":
AchievementAccomplished = true;
quick_info e = gameObject.AddComponent<quick_info>();
e.display_time = 5;
audio.PlayOneShot(AchievementSound);
break;
}
}
}