
using UnityEngine;
using System.Collections;

public class Token : MonoBehaviour
{
    //public GameObject tokenImage;
    public float chance = 30;
    private GameObject token;
    // Use this for initialization
    public void Tokens()
    {
        if (token != null)
        {
            token.GetComponent<TokenScriptBase>().Dispose();
            Destroy(token);
        }

        int f = (int)Random.Range(1, chance);
        int s = (int)Random.Range(1, chance);
        if (f == s)
        {
            int which = Random.Range(1, 4);
            if (which == 1)
            {
                
                token = (GameObject)Instantiate(Test.speedUpToken, this.transform.position + new Vector3(0, 1, 0), new Quaternion(0, 0, 0, 0));
            }
            else if (which == 2)
            {
                token = (GameObject)Instantiate(Test.speedDownToken, this.transform.position + new Vector3(0, 1, 0), new Quaternion(0, 0, 0, 0));
            }
            else if (which == 3)
            {
                token = (GameObject)Instantiate(Test.bonusToken, this.transform.position + new Vector3(0, 1, 0), new Quaternion(0, 0, 0, 0));
            }
        }
    }
    
    // Update is called once per frame
    void Update()
    {
        if (token)
            token.transform.Rotate(new Vector3(0, 1, 0), 60 * Time.deltaTime);
    }
}