forked from JXPorter/OkitaUnity
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExample.cs
More file actions
104 lines (95 loc) · 2.41 KB
/
Example.cs
File metadata and controls
104 lines (95 loc) · 2.41 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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
using UnityEngine;
using System.Collections;
public class Example : MonoBehaviour
{
void Start()
{
// // Array Practice Code
// int[] primes = { 1, 3, 5, 7, 11, 13, 17, 23, 27, 31 };
// int[] fibonacci = {0,1,1,2,3,5,8,13,21,34,55,89,144 };
// int[] powersOfTwo = { 1,2,4,8,16,32,64,128,256,512,1024 };
// ArrayList Numbers = new ArrayList{ primes, fibonacci, powersOfTwo};
// int numArrays = Numbers.Count;
// for(int i = 0; i < numArrays; i++)
// {
// int[] Nums = Numbers [i] as int[];
// int items = Nums.Length;
// for(int j = 0; j < items; j++)
// {
// int Num = Nums [j];
// print (Num);
// }
// }
}
void Update()
{
GameObject[] gos = GameObject.FindGameObjectsWithTag ("Monster");
ArrayList distances = new ArrayList ();
//print (gos.Length);
foreach(GameObject g in gos)
{
Vector3 vec = g.transform.position - transform.position;
float distance = vec.magnitude;
distances.Add (distance);
}
float closestValue = (float)distances[0];
GameObject closestObject = gos [0];
for(int i =0; i < gos.Length; i++)
{
float d = (float)distances [i];
if(d < closestValue)
{
closestObject = gos [i];
closestValue = (float)distances [i];
}
}
//print (distances.Count);
Vector3 up = new Vector3 (0,1,0);
Vector3 start = closestObject.transform.position;
Debug.DrawRay (start,up, Color.green);
GameObject go = GameObject.Find ("Cube");
Vector3 CubePosition = go.transform.position;
Vector3 Up = new Vector3 (0,1,0);
Debug.DrawRay (CubePosition, Up);
}
}
//// Original Code
//public class Example : MonoBehaviour
//{
//
// // Use this for initialization
// void Start()
// {
//
// }
//
// // Update is called once per frame
// void Update()
// {
// GameObject[] gos = GameObject.FindGameObjectsWithTag("Monster");
// ArrayList distances = new ArrayList();
// foreach (GameObject g in gos)
// {
// Vector3 vec = g.transform.position - transform.position;
// float distance = vec.magnitude;
// distances.Add(distance);
// }
//
// float closestValue = (float)distances [0];
// GameObject closestObject = gos [0];
//
// for (int i = 0; i < gos.Length; i++)
// {
// float d = (float)distances [i];
// if (d <= closestValue)
// {
// closestObject = gos [i];
// closestValue = d;
// }
// }
//
// Vector3 up = new Vector3(0, 1, 0);
// Vector3 start = closestObject.transform.position;
// Debug.DrawRay(start, up);
// }
//}