A*関係,複数キャラクタを複数のポイントに向かわせる

作成中

using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using UnityStandardAssets.Characters.ThirdPerson;

public class myscript : MonoBehaviour {
	
	public GameObject myInstance;//for prefab
	public GameObject myGoal;//for goal object
	public int sakusei = 10;//chara duplicate count
	public GameObject targetbj;//GameObject of chara target
	Transform targetPos;//位置情報用の変数
	GameObject NavObj;//NavMeshのついているGameObject
	NavMeshAgent myNav;//NavMeshAgent入れ用

	List<Vector3> myPoint = new List<Vector3>();//ゴール地点リスト用

	// Use this for initialization
	void Start () {
		myPoint = new List<Vector3>();//リスト初期化
		myPoint.Add (new Vector3 (0.0f, 0.5f, -5.0f));//リスト項目追加   
		myPoint.Add (new Vector3 (-20f, 0.5f, 14f));
		myPoint.Add (new Vector3 (20f, 0.5f, 14f));

		//ゴール地点3個作成用(テスト)
		GameObject goalObj = Instantiate (myGoal, myPoint [0], Quaternion.identity) as GameObject;
		goalObj.name =  "goal1";
		goalObj = Instantiate (myGoal, myPoint [1], Quaternion.identity) as GameObject;
		goalObj.name =  "goal2";
		goalObj = Instantiate (myGoal, myPoint [2], Quaternion.identity) as GameObject;
		goalObj.name =  "goal3";

		//キャラn体作成
		for (int i = 0; i < sakusei; i++) {
			GameObject go = Instantiate (myInstance, new Vector3 (i + 1.0f, 0, 0), Quaternion.identity) as GameObject;
			string myAIname =  "AI" + i.ToString ();
			go.name = myAIname;
			int divideInt = i % 3;
			if (divideInt == 0) {
				GameObject my1 = GameObject.Find("goal1");
				targetPos = my1.GetComponent<Transform> ();
	
			}else if (divideInt == 1) {
				GameObject my2 = GameObject.Find("goal2");
				targetPos = my2.GetComponent<Transform> ();
			}else if (divideInt == 2) {
				GameObject my3 = GameObject.Find("goal3");
				targetPos = my3.GetComponent<Transform> ();
			}

		myNav = NavObj.GetComponent<NavMeshAgent> ();//Get Nav mesh from current object

			myNav.SetDestination (targetPos.position);//set goal pos of myNav
			myNav.stoppingDistance = 3.0f;//offset distance from goal point...korenaito guriguri suru
			AICharacterControl  myTar  = NavObj.GetComponent<AICharacterControl>();//find component of NabObj
			myTar.target = targetPos;//set Goal variable

		}
	}
	
	// tsukotenai
	void Update () {
	
	}
}