using UnityEngine;
using System.Collections;

public class sizechanging : MonoBehaviour {
    public float pingpoo = 0;
    public float timeDown = 0;
    public float ticNumber = 0;
    public float keyThresh = 8;
    public bool isEffect = false;
    public GameObject playerRef;

	// Use this for initialization
	void Start () {
        playerRef = GameObject.FindGameObjectWithTag("Player");
        transform.localScale = new Vector3(pingpoo, transform.localScale.y, pingpoo);
        ticNumber = keyThresh;

    }
    void OnTriggerEnter(Collider other)
    {
        if (other.gameObject.tag == "Player")
        {
            other.GetComponent<Rigidbody>().velocity = new Vector3(0, 10, 0);
        }
    }

    public void KeytarMakeBeat() {
        timeDown = 4f;
        ticNumber++;
        //Debug.Log("Error: Keytar has broken a key");
    }

    // Update is called once per frame
    void Update () {
        

        
        if (timeDown > 0) {
            timeDown -= 0.1f;
            pingpoo = Mathf.PingPong((Time.time * 20), timeDown);
            transform.localScale = new Vector3(pingpoo, transform.localScale.y, pingpoo);
        }
        if (ticNumber >= keyThresh) {
            ticNumber = 0;
            if (!isEffect) {
                transform.position = new Vector3(Random.Range(-11, 11), Random.Range(1, 4), Random.Range((playerRef.transform.position.z - 20), playerRef.transform.position.z));
            }
            
            
        }



        //if (timedown <= 0) {
        //    Destroy(gameObject);
        //}
    }
}
