Exemple #1
0
	// Use this for initialization
	void Start ()
	{
		Init();

		if (side == 0) guardShip = GameObject.Find("BattleCruiser").GetComponent<TestShip>();
		else guardShip = null;

		targetCooldown = 0.0f;
		FindTarget();

		gunCooldown = 0.0f;
		canShoot = true;
	}
Exemple #2
0
	void FindTarget()
	{
		if (side == 1)
		{
			if (Random.Range(0, 2) == 0)
			{
				targetShip = GameObject.Find("BattleCruiser").GetComponent<TestShip>();
				return;
			}
		}

		GameObject root = GameObject.Find(side == 0 ? "Enemy" : "Me");
		int numTargets = root.transform.childCount;

		targetShip = null;
		float d = float.MaxValue;

		for (int i = 0; i < numTargets; i++)
		{
			TestShip curShip = root.transform.GetChild(i).GetComponent<TestShip>();

			Vector3 u = (side == 0 ? curShip.pos - guardShip.pos : curShip.pos - pos);
			u.y = 0.0f;

			float l = u.magnitude;
			if (l < d)
			{
				d = l;
				targetShip = curShip;
			}
		}

		if (targetShip == null) targetShip = guardShip;

		targetCooldown = Random.Range(8.0f, 10.0f);
	}