-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcoin.cs
31 lines (24 loc) · 977 Bytes
/
coin.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
using UnityEngine;
using System.Collections;
public class coin : MonoBehaviour
{
public GameObject[] ob1; // new gameobect for coin spawning
public Transform campos1; // chosing the camera
void Start()
{
CoinMaker(); // calling the function
}
void Update()
{
transform.Translate(Vector3.down * PlayerPrefs.GetFloat("speed") * Time.deltaTime);
}
void CoinMaker()
{
GameObject clone = (GameObject)Instantiate(ob1[Random.Range(0, ob1.Length)], transform.position, Quaternion.identity); // cloneing the coin
clone.name = "Coin"; // assigning name to the clone
clone.AddComponent<BoxCollider2D>(); // adding box collider to the clone
clone.GetComponent<BoxCollider2D>().isTrigger = true; // setting the box collider trigger
float xyx = Random.Range(7, 8); // time between each coins
Invoke("CoinMaker", xyx); // invoiking the function with respect to time xyz
}
}