itsharshdeep

globalFlock.cs

Mar 10th, 2017
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.13 KB | None | 0 0
  1. using UnityEngine;
  2. using System.Collections;
  3.  
  4. public class globalFlock : MonoBehaviour {
  5.  
  6.     public GameObject fishPrefab;
  7.     public GameObject gol;
  8.     public static int tankSize = 5;
  9.  
  10.     static int numFish = 20;
  11.     public static GameObject[] allFish = new GameObject[numFish];
  12.  
  13.     public static Vector3 goalPos = Vector3.zero;
  14.  
  15.     // Use this for initialization
  16.     void Start ()
  17.     {
  18.         for(int i = 0; i < numFish; i++)
  19.         {
  20.             Vector3 pos = new Vector3(Random.Range(-tankSize,tankSize),
  21.                                       Random.Range(-tankSize,tankSize),
  22.                                       Random.Range(-tankSize,tankSize));
  23.             GameObject g = (GameObject) Instantiate(fishPrefab);
  24.             g.transform.SetParent (transform);
  25.             g.transform.localPosition = pos;
  26.             g.transform.rotation = Quaternion.identity;
  27.             allFish [i] = g;
  28.         }
  29.     }
  30.    
  31.     // Update is called once per frame
  32.     void Update ()
  33.     {
  34.         if(Random.Range(0,10000) < 50)
  35.         {
  36.             goalPos = new Vector3(Random.Range(-tankSize,tankSize),
  37.                                   Random.Range(-tankSize,tankSize),
  38.                                   Random.Range(-tankSize,tankSize));
  39.             gol.transform.localPosition = goalPos;
  40.         }
  41.     }
  42. }
Add Comment
Please, Sign In to add comment