예제 #1
0
 /// <summary>
 /// Sets the reference to the manager, and assigns the bird to the foreground or background
 /// </summary>
 public void Initialize(BirdManager man, bool isForeground)
 {
     manager          = man;
     isForegroundBird = isForeground;
     isInitialized    = true;
     flyToPos         = manager.GetNewFlyPos(transform.position, transform.forward, isForegroundBird);
 }
예제 #2
0
    // Use this for initialization
    void Start()
    {
        mainCamera = Camera.main.GetComponent <Camera>();

        b_Manager = GameObject.Find("Bird Manager").GetComponent <BirdManager>();

//		lines = GameObject.Find("Goal Manager").GetComponent<>()
    }
예제 #3
0
    private void GetBirdsGameObject()
    {
        birdGameObject = GameObject.Find("Birds");

        if (birdGameObject)
        {
            birdManager = birdGameObject.GetComponent <BirdManager>();
            SetupBirdsActions();
        }
    }
예제 #4
0
    public override void OnInspectorGUI()
    {
        DrawDefaultInspector();
        BirdManager birdManager = (BirdManager)target;

        if (GUILayout.Button("UpdateLandingSpots"))
        {
            birdManager.UpdateListOfLandingSpots();
        }
    }
예제 #5
0
    void Start()
    {
        rb           = GetComponent <Rigidbody2D>();
        playerSprite = GetComponent <SpriteRenderer>();

        birdManager = GameObject.Find("Bird Manager");
        b_Manager   = birdManager.GetComponent <BirdManager>();

        currentForce = force;
    }
    void Awake()
    {
        if (hasInitialized)
        {
            return;
        }
        Instance = this;
        birdList = new List <Bird>();

        hasInitialized = true;
    }
예제 #7
0
	void Awake() {
		instance = this;

		goodBounds = new Bounds();
		badBounds = new Bounds();
		foreach (var child in GoodPrefab.GetComponentsInChildren<SpriteRenderer>()) {
			goodBounds.Encapsulate (child.bounds);
		}
		foreach (var child in BadPrefab.GetComponentsInChildren<SpriteRenderer>()) {
			badBounds.Encapsulate (child.bounds);
		}
	}
예제 #8
0
    void PerformCurrentAction()
    {
        switch (currentAction)
        {
        default:
            break;

        case Action.FLY_AWAY:

            acceleration = new Vector2(direction * 1, 1);

            if (velocity.magnitude >= maxSpeed)
            {
                velocity = velocity.normalized * maxSpeed;
            }

            break;

        case Action.SCARED:

            Vector2 directionVector = (fleeTarget.getRandomPos(transform.localScale / 2) - transform.position);

            if (directionVector.magnitude <= manager.birdFleeRadius)
            {
                manager.removeBird(this);
                manager = fleeTarget;
                manager.addBird(this);

                currentAction = Action.STAY;
                RandomizeWaitTime();

                velocity = Vector2.zero;
                fleeTime = Time.fixedTime;
                return;
            }


            acceleration = (directionVector.normalized * maxSpeed) - velocity;
            acceleration = acceleration.normalized * 0.3f;

            Debug.DrawRay(transform.position, velocity.normalized * 10f, Color.green);
            Debug.DrawRay(transform.position, acceleration.normalized * 10f, Color.red);
            Debug.DrawRay(transform.position, directionVector.normalized * 10f, Color.yellow);

            if (velocity.magnitude >= maxSpeed)
            {
                velocity = velocity.normalized * maxSpeed;
            }

            break;
        }
    }
예제 #9
0
    private void Awake()
    {
        instance = this;

        bounding = new AABB(transform.position, size);

        for (int i = 0; i < birdCount; i++)
        {
            Vector3 pos  = transform.position + new Vector3(size.x * Random.value, size.y * Random.value, size.z * Random.value) - (size / 2);
            Bird    bird = Instantiate(birdPrefab, pos, Quaternion.identity);
            bird.aabb = bounding;
        }
    }
예제 #10
0
    public void FlyToNewZone()
    {
        BirdManager zone = manager.getNewZone();

        if (zone == null)
        {
            currentAction = Action.FLY_AWAY;
            return;
        }

        fleeTarget = zone;
        velocity   = Vector2.up * maxSpeed;
        waitTime   = manager.birdMaxFleeTime;
    }
예제 #11
0
    private void Awake()
    {
        if (!birdManager)
        {
            birdManager = FindObjectOfType <BirdManager>();
        }

        birds        = new List <BirdBehavior>();
        landingSpots = new List <BirdLandingSpot>();

        if (!cam)
        {
            cam = Camera.main;
        }
    }
예제 #12
0
파일: GameManager.cs 프로젝트: otiket/Boid
    // Update is called once per frame
    void Update()
    {
        float averageVx = 0;
        float averageVy = 0;

        foreach (GameObject bird in birds)
        {
            bird.GetComponent <BirdManager>().ClearVector();
            averageVx += bird.GetComponent <BirdManager>().GetVx();
            averageVy += bird.GetComponent <BirdManager>().GetVy();
        }
        averageVx /= N;
        averageVy /= N;
        foreach (GameObject bird in birds)
        {
            bird.GetComponent <BirdManager>().Rotate(GetCenter());
        }

        if (Input.GetMouseButtonDown(0))
        {
            BirdManager.SetCenter(Camera.main.ScreenToWorldPoint(Input.mousePosition));
        }
    }
예제 #13
0
 private void Awake()
 {
     lineRenderer = GetComponent <LineRenderer>();
     animator     = GetComponent <Animator>();
     birdManager  = FindObjectOfType <BirdManager>();
 }
예제 #14
0
 void Awake()
 {
     instance = this;
 }