/
GoldScript.cs
74 lines (57 loc) · 1.7 KB
/
GoldScript.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
using UnityEngine;
using System.Collections;
public class GoldScript : MonoBehaviour {
private float maxY;
private float minY;
private int direction = 1;
public bool inPlay=true;
private bool releaseCreate=false;
private GameManager score;
private scoreTransformer scoreTransform;
public AudioClip gold1;
public AudioClip gold2;
void Start () {
score=GameObject.Find("Canvas").GetComponent<GameManager>();
scoreTransform=GameObject.Find("score100(Clone)").GetComponent<scoreTransformer>();
maxY = this.transform.position.y + .5f;
minY = maxY - 1.0f;
}
void Update () {
this.transform.position = new Vector2 (this.transform.position.x, this.transform.position.y +(direction * 0.05f));
if (this.transform.position.y > maxY)
direction = -1;
if (this.transform.position.y < minY)
direction = 1;
if(!inPlay && !releaseCreate)
Respawn();
}
void OnTriggerEnter2D(Collider2D coll)
{
if (coll.gameObject.tag == "Player")
{
SoundManager.instance.RandomizeSfx (gold1,gold2);
Vector2 goldPos=transform.position;
//string type="s100";
scoreTransform.AddScore100(goldPos);
inPlay=false;
this.transform.position = new Vector2(this.transform.position.x, this.transform.position.y + 30.0f);
score.score+=100;
}
}
void Respawn()
{
releaseCreate=true;
Invoke("PlaceGold",(float)Random.Range(1,5));
}
void PlaceGold()
{
inPlay=true;
releaseCreate=false;
if(scoreTransform.level!=null){
GameObject tmpTile=GameObject.Find ("MainCamera").GetComponent<LevelCreator>().tilePos;
this.transform.position=new Vector2(tmpTile.transform.position.x,tmpTile.transform.position.y+3.5f);
}
maxY = this.transform.position.y + .5f;
minY = maxY - 1.0f;
}
}