1
|
public
GameObject monsterPrefab;
private
GameObject monster;
|
1
2
|
private
bool
canPlaceMonster(){
return
monster ==
null
;[/size][/font]
[font=微软雅黑][size=3]}
|
01
02
03
04
05
06
07
08
09
10
11
12
13
|
//1
void
OnMouseUp(){
//2
if
(canPlaceMonster()){
//3
monster =(GameObject)
Instantiate(monsterPrefab, transform.position, Quaternion.identity);
//4
AudioSource audioSource=gameObject.GetComponent
audioSource.PlayOneShot(audioSource.clip);
// TODO: Deduct gold
}
}
|
1
2
3
4
|
[System.Serializable]
public
class
MonsterLevel{
public
int
cost;
public
GameObject visualization;
}
|
|
using
System.Collections.Generic;
|
|
public
List
|
|
private
MonsterLevel currentLevel;
|
01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
16
17
18
19
20
21
22
|
//1
public
MonsterLevel CurrentLevel{
//2
get
{
return
currentLevel;
}
//3
set
{
currentLevel= value;
int
currentLevelIndex=levels.IndexOf(currentLevel);
GameObject levelVisualization= levels[currentLevelIndex].visualization;
for
(
int
i=0;i if
(levelVisualization!=
null
){
if
(i==currentLevelIndex){
levels[i].visualization.SetActive(
true
);[/i]
}
else
{
[i] levels.visualization.SetActive(
false
);
}
}
}
}
}
|
1
2
|
void
OnEnable(){
CurrentLevel= levels[0];
}
|