-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLeftScrollButton.cs
More file actions
99 lines (80 loc) · 3.23 KB
/
Copy pathLeftScrollButton.cs
File metadata and controls
99 lines (80 loc) · 3.23 KB
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class LeftScrollButton : MonoBehaviour {
public AudioClip acClickOn;
private PlayerController pScript;
private GameObject scrollView;
private Button button;
private AudioSource audioOut;
private ScrollRect scrollRect;
private Text charCost;
private BuyButton buyButton;
private MenuButton menuButton;
// Use this for initialization
void Start () {
scrollView = GameObject.FindGameObjectWithTag("ScrollView");
if (scrollView == null)
Debug.Log("Left Scroll button could not get the scrollview reference.");
else
scrollRect = scrollView.GetComponent<ScrollRect>();
if(scrollRect == null)
{
Debug.Log("Left Scroll button could not get the scroll rect reference.");
}
button = GetComponent<Button>();
if (button == null)
Debug.Log("Left Scroll button script could not get a reference to the button sript.");
else
button.onClick.AddListener(ClickLeft);
audioOut = GetComponent<AudioSource>();
if (audioOut == null)
Debug.Log("Left Scroll button couldnt get its Audio Source component.");
charCost = GameObject.FindGameObjectWithTag("uiCharCostField").GetComponent<Text>();
if (charCost == null)
Debug.Log("Left Scroll button script could not get a reference to the Character Cost Text component.");
pScript = GameObject.FindGameObjectWithTag("PlayerController").GetComponent<PlayerController>();
if (pScript == null)
Debug.Log("Left Scroll script could not get a reference to the player controller.");
buyButton = GameObject.FindGameObjectWithTag("uiBuyButton").GetComponent<BuyButton>();
if (buyButton == null)
{
Debug.Log("Left Scroll button couldnt get a reference to the Buy Button script.");
}
menuButton = GameObject.FindGameObjectWithTag("MenuButton").GetComponent<MenuButton>();
if (menuButton == null)
{
Debug.Log("Left Scroll button couldnt get a reference to the menu Button script.");
}
}
// Update is called once per frame
void Update () {
Image img = GetComponent<Image>();
Color cA = pScript.GetCharColorA();
Color cB = pScript.GetCharColorB();
Color foo = Color.Lerp(cB, cA, pScript.GetLerpVal());
foo.a = 255f;
img.color = foo;
}
public void ClickLeft()
{
float move = scrollRect.horizontalNormalizedPosition;
if(move > 0)
{
audioOut.PlayOneShot(acClickOn, 0.8f);
scrollRect.inertia = true;
scrollRect.velocity = new Vector2(-0.3f, 0);
//charCost.text = "";
}
Button btn = buyButton.GetComponentInParent<Button>();
btn.enabled = false;
buyButton.SetWiggle(false);
buyButton.SetCharIndex(0, null);
//menuButton.ClearCharFields();
}
public void StopScrolling()
{
scrollRect.velocity = new Vector2(0, 0);
}
}