-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcoinscript.cs
More file actions
35 lines (26 loc) · 883 Bytes
/
coinscript.cs
File metadata and controls
35 lines (26 loc) · 883 Bytes
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
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
public class coinscript : MonoBehaviour {
private score thecoinscore;
public float speed = 1; // Use this for initialization
void Start()
{
thecoinscore = FindObjectOfType<score>();
}
void Update()
{
transform.position += Vector3.down * 2 * speed * Time.deltaTime; // transforming the position
}
void OnCollisionEnter2D(Collision2D col2)
{
Debug.Log("trigger3");
if (col2.gameObject.layer == 8) // Checking the colliton with the player
{
thecoinscore.coinscore = thecoinscore.coinscore + 1; // Adding coin score
Debug.Log("coinscore");
GameObject coins1 = GameObject.Find("Coin"); // finding the game object
Destroy(coins1); // destrroying the coin
}
}
}