RaycastController.cs
1.44 KB
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
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);
}
}