Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Converted from UnityScript to C# at http://www.M2H.nl/files/js_to_c.php - by Mike Hergaarden
- // Do test the code! You usually need to change a few small bits.
- using UnityEngine;
- using System.Collections;
- public class MYCLASSNAME : MonoBehaviour {
- ArrayList balls;
- void Start (){
- balls = new ArrayList();
- // Instantiate ball for test-purpose
- FIXME_VAR_TYPE newBall= Instantiate(ballPrefab,Vector3(10.0f,0.0f,10.0f),Quaternion.identity);
- balls.Add(newBall.gameObject); // Notice .gameObject
- }
- GameObject findClosestBall ( int ball_x , int ball_y ){
- GameObject closestBall;
- float shortestDistance = 9999;
- Vector3 ballPos;
- Vector3 coordinatePos;
- Vector3 distanceVector;
- foreach(GameObject ball in balls){
- ballPos = ball.transform.position;
- coordinatePos = Vector3(ball_x, GameController.y_height, ball_y);
- distanceVector = ballPos - coordinatePos;
- if (distanceVector.magnitude < shortestDistance){
- closestBall = ball;
- shortestDistance = distanceVector.magnitude;
- }
- }
- return closestBall;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement