-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAchievement.cs
71 lines (69 loc) · 2.38 KB
/
Achievement.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UltraAchievement;
public class Achievement : MonoBehaviour
{
private float endTimer = 0;
private float startTimer = 0;
private float animTimer;
private bool endTimerStarted = false;
private bool startTimerStarted = false;
private RectTransform rect;
private Image icon;
private Text title,description;
public void InitAchievement(string iconPath, string name = "Achievement", string desc = "Example description")
{
rect = GetComponent<RectTransform>();
title = transform.GetChild(0).GetComponent<Text>();
description = transform.GetChild(1).GetComponent<Text>();
icon = transform.GetChild(2).GetComponent<Image>();
title.text = name;
description.text = desc;
icon.sprite = Core.LoadSprite(iconPath,Vector4.zero,100);
rect.anchoredPosition = new Vector2(400,0);
startTimerStarted = true;
}
public void InitAchievementI(Sprite ico, string name = "Achievement", string desc = "Example description")
{
rect = GetComponent<RectTransform>();
title = transform.GetChild(0).GetComponent<Text>();
description = transform.GetChild(1).GetComponent<Text>();
icon = GetComponentInChildren<Image>();
title.text = name;
description.text = desc;
icon.sprite = ico;
rect.anchoredPosition = new Vector2(400,0);
startTimerStarted = true;
}
void Update()
{
if(startTimerStarted)
{
startTimer += Time.deltaTime;
animTimer += Time.deltaTime * 1.35f;
if (animTimer >= 1) animTimer = 1;
rect.anchoredPosition = new Vector2(Mathf.Lerp(400f, 0f, animTimer),0);
if(startTimer >= 5)
{
animTimer = 0;
endTimerStarted = true;
startTimerStarted = false;
}
}
if(endTimerStarted)
{
endTimer += Time.deltaTime;
animTimer += Time.deltaTime * 1.35f;
if (animTimer >= 1) animTimer = 1;
rect.anchoredPosition = new Vector2(Mathf.Lerp(0f, 400f, animTimer), 0);
if (endTimer >= 5)
{
endTimerStarted = false;
Destroy(this.gameObject);
}
}
}
}