-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMoveTo.cs
162 lines (160 loc) · 4.97 KB
/
MoveTo.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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.EventSystems;
public class MoveTo : MonoBehaviour, IPointerEnterHandler, IPointerExitHandler
{
public GameObject livingRoom;
public GameObject bathRoom;
public GameObject kitchen;
public GameObject playRoom;
public GameObject garden;
public GameObject cat;
public MessageManager message;
Button btn;
string btnName;
string txt;
void Start()
{
btn=gameObject.GetComponent<Button>();
if(btn.name!="ToUp")
{
btn.GetComponent<Image>().sprite=Resources.Load<Sprite>("Picture/nothing");
btn.enabled =false;
}
btnName="";
btn.onClick.AddListener(OnClick);
}
public void OnPointerEnter(PointerEventData eventData)
{
if (eventData.pointerCurrentRaycast.gameObject != null)
{
btn.enabled =true;
this.btnName=eventData.pointerCurrentRaycast.gameObject.name;
if(btnName!="ToUp")
{
btn.GetComponent<Image>().sprite=Resources.Load<Sprite>("Picture/bg_butt");
}
if(btnName=="ToRight")
{
if(livingRoom.activeInHierarchy){
message.SetMessage(true,"В игровую!");
}
else if(kitchen.activeInHierarchy)
{
message.SetMessage(true,"В гостинную!");
}
else if(bathRoom.activeInHierarchy)
{
message.SetMessage(true,"На кухню!");
}
else
{
btn.enabled =false;
btn.GetComponent<Image>().sprite=Resources.Load<Sprite>("Picture/nothing");
}
}
else if(btnName=="ToLeft")
{
if(livingRoom.activeInHierarchy){
message.SetMessage(true,"На кухню!");
}
else if(kitchen.activeInHierarchy)
{
message.SetMessage(true,"В ванную!");
}
else if(playRoom.activeInHierarchy)
{
message.SetMessage(true,"В гостинную!");
}
else
{
btn.enabled =false;
btn.GetComponent<Image>().sprite=Resources.Load<Sprite>("Picture/nothing");
}
}
else if(btnName=="ToDown")
{
if(garden.activeInHierarchy){
message.SetMessage(true,"В кухню!");
}
else
{
btn.enabled =false;
btn.GetComponent<Image>().sprite=Resources.Load<Sprite>("Picture/nothing");
}
}
else if(btnName=="ToUp")
{
message.SetMessage(true,"В сад!");
}
}
}
public void OnPointerExit(PointerEventData eventData)
{
if(btnName!="ToUp"){
btn.GetComponent<Image>().sprite=Resources.Load<Sprite>("Picture/nothing");
btn.enabled =false;
}
this.btnName="";
message.SetMessage(false,"");
}
void OnClick()
{
if(btnName=="ToRight")
{
if(livingRoom.activeInHierarchy){
livingRoom.SetActive(false);
playRoom.SetActive(true);
MovingPet(playRoom);
}
else if(kitchen.activeInHierarchy)
{
kitchen.SetActive(false);
livingRoom.SetActive(true);
MovingPet(livingRoom);
}
else if(bathRoom.activeInHierarchy)
{
bathRoom.SetActive(false);
kitchen.SetActive(true);
MovingPet(kitchen);
}
}
else if(btnName=="ToLeft")
{
if(livingRoom.activeInHierarchy){
livingRoom.SetActive(false);
kitchen.SetActive(true);
MovingPet(kitchen);
}
else if(kitchen.activeInHierarchy)
{
kitchen.SetActive(false);
bathRoom.SetActive(true);
MovingPet(bathRoom);
}
else if(playRoom.activeInHierarchy)
{
playRoom.SetActive(false);
livingRoom.SetActive(true);
MovingPet(livingRoom);
}
}
else if(btnName=="ToDown")
{
garden.SetActive(false);
kitchen.SetActive(true);
MovingPet(kitchen);
}
else if(btnName=="ToUp")
{
kitchen.SetActive(false);
garden.SetActive(true);
MovingPet(garden);
}
}
void MovingPet(GameObject obj)
{
cat.transform.SetParent(obj.GetComponent<Transform>());
}
}