using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class ProjoScript : MonoBehaviour
{
    //public float valueX, valueY, valueZ;

    public Transform[] targets;
    Transform currentTarget;

    public float timer;
    float currentTimer;
    float randomValue;

    // Start is called before the first frame update
    void Start()
    {
        currentTimer = 0;
        Transform targetss = GameObject.Find("ProjoTargets").transform;
        targets = new Transform[targetss.childCount];
        for (int i = 0; i< targetss.childCount ; i++)
        {
            targets[i] = targetss.GetChild(i);
        }        
        //InvokeRepeating("ChooseNewTarget",1f,1.2f+Random.value);
        randomValue = Random.value;
    }

    void Update()
    {
        currentTimer+=Time.deltaTime;

        if (currentTimer > timer + randomValue)
        {
            randomValue = Random.value;
            currentTimer = 0;
            currentTarget = targets[Random.Range(0,targets.Length)];
            transform.LookAt(currentTarget);
        }

    } 

    void NewTimer(float newValue)
    {
        timer = newValue;
    }
}


