RaycastController.cs 1.44 KB
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class RaycastController : MonoBehaviour
{

    public float maxDistanceRay= 100f;
    public static RaycastController instance;
    public Text birdName;
    public Transform gunFlashTarget;
    public float fireRate = 1.6f;
    private bool nextShot = true;
    private string objName = "";

    AudioSource audio;

    void Awake() {
        if (instance == null) {
            instance = this;
        }
    }
    // Start is called before the first frame update
    void Start()
    {
        StartCoroutine(spawnNewBird());
    }

    // Update is called once per frame
    void Update()
    {
        
    }
    private IEnumerator spawnNewBird() {
        yield return new WaitForSeconds (3f);
        //Spawn new bird
        GameObject newBird = Instantiate(Resources.Load("Bird_Asset", typeof(GameObject))) as GameObject;

        //Make Bird Child ImageTarget
        newBird.transform.parent = GameObject.Find("ImageTarget").transform;

        //Scale Bird
        newBird.transform.localScale = new Vector3(10f,10f,10f);

        //Random Start Position
        Vector3 temp;
        temp.x = Random.Range(-4.8f/2, 4.8f/2);
        temp.y = Random.Range(1f/2, 5f/2);
        temp.z = Random.Range(-4.8f/2, 4.8f/2);
        newBird.transform.position = new Vector3(temp.x,temp.y,temp.z);
    }
}