-
Notifications
You must be signed in to change notification settings - Fork 2
/
shopButton.cs
82 lines (70 loc) · 1.6 KB
/
shopButton.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
72
73
74
75
76
77
78
79
80
81
82
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
//the "Build weapon" button
public class shopButton : MonoBehaviour {
public Renderer rend;
public Vector2 playerPosition;
public Vector2 tilePosition;
private bool chosen;
public bool current;
public Color mouseOver;
public Color chosenColor;
public Color wunengColor;
public bool valid;
public bool mouseon;
public bool mouseDown;
public GameObject controller;
public GameObject statsCtrl;
public statsController dataBase;
public GameObject currentWeapons;
public menu playerMenu;
public int weaponId;
void Start() {
rend = GetComponent<Renderer>();
controller = GameObject.Find ("GameController(Clone)");
statsCtrl = GameObject.Find("gameData");
dataBase = statsCtrl.GetComponent<statsController> ();
playerPosition = new Vector2 (0, 0);
valid = true;
mouseon = false;
}
void OnMouseOver(){
mouseon = true;
}
void OnMouseUp() {
if (valid&&(!current)&&mouseon) {
build();
}
mouseDown = false;
}
void OnMouseDown() {
if (valid) {
mouseDown = true;
rend.material.color = chosenColor;
}
}
void OnMouseExit() {
mouseon = false;
mouseDown = false;
}
void Update(){
if (playerMenu.weapons.Find((x) => { return x == weaponId; })==weaponId){
current = true;
} else {
current = false;
}
if (!valid) {
rend.material.color = wunengColor;
}else if(current||mouseDown){
rend.material.color = chosenColor;
}else if(mouseon){
rend.material.color = mouseOver;
}else{
rend.material.color = Color.white;
}
}
void build(){
playerMenu.addItem (weaponId);
}
}