// Update is called once per frame
    void Update()
    {
        Vector3 pos = Simulator.Instance.getAgentPosition(_agentHandler);

        transform.position = pos;
        target             = CameraOperator2.GetDestination();
        target.y           = 28;
        Simulator.Instance.setAgentPrefVelocity(_agentHandler, target - transform.position);
    }
예제 #2
0
//	private Vector3 processedVectorPath;
    // Update is called once per frame
    void Update()
    {
        //unitselected ();

        Debug.Log(Simulator.Instance.getNumAgents());
        if (GetComponent <Renderer> ().isVisible&& Input.GetMouseButton(0))           //gameObject.tag =="Unit") {

        {
            if (!selectedByClick)
            {
                Vector3 camPos = Camera.main.WorldToScreenPoint(transform.position);
                camPos.y = CameraOperator2.InverMouseY(camPos.y);
                selected = CameraOperator2.selection.Contains(camPos);
                //selectedAI.Add(CameraOperator2.selection.Contains (camPos));
            }
            if (selected && projector == null)               //selectedAI.Contains(this.gameObject) ) {
            {
                projector = (GameObject)GameObject.Instantiate(selectionProjector);
                projector.transform.parent        = transform;
                projector.transform.localPosition = new Vector3(0, 28, 0);
            }
            else if (!selected && projector != null)
            {
                GameObject.Destroy(projector);
                projector = null;
            }
        }
        if (selected)
        {
            if (!camShot.selectedAI.Contains(gameObject))
            {
                camShot.selectedAI.Add(gameObject);
            }

            //selectedAI.Add (this.gameObject);
            if (Input.GetMouseButtonUp(1))
            {
                //newPosition = this.transform.position; //Set the "new" position equal to the current player's position
                targetPosition = CameraOperator2.GetDestination();
                Vector3 center = Vector3.zero;
                foreach (GameObject unit in camShot.selectedAI)
                {
                    if (unit != null)
                    {
                        center += unit.transform.position;
                    }
                }
                //Debug.Log (total);
                center /= camShot.selectedAI.Count;


                targetPosition += transform.position - center;
            }
        }
        else if (!selected)
        {
            camShot.selectedAI.Remove(gameObject);
        }

        Vector3 pos = Simulator.Instance.getAgentPosition(_agentHandler);

        transform.position = pos;

//		if (CekPosisiMusuh == false) {
//
//		} else if (CekPosisiMusuh == true) {
//
//		}

        if (this.gameObject.name == "Yamato" || this.gameObject.name == "Yamato(Clone)" || this.gameObject.name == "Kagero" || this.gameObject.name == "Kagero(Clone)" || this.gameObject.name == "Mogami" || this.gameObject.name == "Mogami(Clone)")
        {
            targetPosition = PathEnemy.targetqueue;
        }

        dir = targetPosition - transform.position;
//		if (this.gameObject.name == "Iowa(Clone)") {
//			Debug.Log (Simulator.Instance.getAgentMaxSpeed(_agentHandler));
//		}
        Simulator.Instance.setAgentPrefVelocity(_agentHandler, dir);

        //Debug.DrawRay (transform.position, targetPosition);
        if (CekPosisiMusuh == false)
        {
            Vector3 v = Simulator.Instance.getAgentVelocity(_agentHandler);
            transform.rotation = Quaternion.LookRotation(new Vector3(v.x, 0, v.z));
        }

        else if (CekPosisiMusuh == true)
        {
            if (EnemyCollider != null)
            {
                if (this.gameObject.name == "Iowa" || this.gameObject.name == "Iowa(Clone)" || this.gameObject.name == "Benson" || this.gameObject.name == "Benson(Clone)" || this.gameObject.name == "Baltimore" || this.gameObject.name == "Baltimore(Clone)")
                {
                    Simulator.Instance.setAgentMaxSpeed(_agentHandler, 0);
                    Quaternion targetrotation = Quaternion.LookRotation(EnemyCollider.transform.position - transform.position);
                    float      str            = Mathf.Min(strength * Time.deltaTime, 1);
                    transform.rotation = Quaternion.Lerp(transform.rotation, targetrotation, str);
                }
            }
            else if (UnitCollider != null)
            {
                if (this.gameObject.name == "Yamato" || this.gameObject.name == "Yamato(Clone)" || this.gameObject.name == "Kagero" || this.gameObject.name == "Kagero(Clone)" || this.gameObject.name == "Mogami" || this.gameObject.name == "Mogami(Clone)")
                {
                    Simulator.Instance.setAgentMaxSpeed(_agentHandler, 0);
                    Quaternion targetrotation = Quaternion.LookRotation(UnitCollider.transform.position - transform.position);
                    float      str            = Mathf.Min(strength * Time.deltaTime, 1);
                    transform.rotation = Quaternion.Lerp(transform.rotation, targetrotation, str);
                    //Debug.Log ("musuh nembak");
                }
            }
            else if (EnemyCollider == null)
            {
                if (this.gameObject.name == "Iowa" || this.gameObject.name == "Iowa(Clone)")
                {
                    this.gameObject.GetComponent <AttackIowa> ().stopAttack();
                    //gameObject.GetComponent<NavMeshAgent> ().Resume ();
                }
                else if (this.gameObject.name == "Benson" || this.gameObject.name == "Benson(Clone)")
                {
                    this.gameObject.GetComponent <AttackDestroyer> ().stopAttack();
                    //gameObject.GetComponent<NavMeshAgent> ().Resume ();
                }
                else if (this.gameObject.name == "Baltimore" || this.gameObject.name == "Baltimore(Clone)")
                {
                    this.gameObject.GetComponent <AttackCruiser> ().stopAttack();
                    //gameObject.GetComponent<NavMeshAgent> ().Resume ();
                }
                else if (this.gameObject.name == "Yamato" || this.gameObject.name == "Yamato(Clone)")
                {
                    this.gameObject.GetComponent <AttackIowa> ().stopAttack();
                    //gameObject.GetComponent<NavMeshAgent> ().Resume ();
                }
                else if (this.gameObject.name == "Kagero" || this.gameObject.name == "Kagero(Clone)")
                {
                    this.gameObject.GetComponent <AttackDestroyer> ().stopAttack();
                    //gameObject.GetComponent<NavMeshAgent> ().Resume ();
                }
                else if (this.gameObject.name == "Mogami" || this.gameObject.name == "Mogami(Clone)")
                {
                    this.gameObject.GetComponent <AttackCruiser> ().stopAttack();
                    //gameObject.GetComponent<NavMeshAgent> ().Resume ();
                }
                CekPosisiMusuh = false;
                Simulator.Instance.setAgentMaxSpeed(_agentHandler, 20);
            }
            //Debug.Log ("unit bisa");
//			else if (UnitCollider == null) {
//				if (this.gameObject.name == "Yamato" || this.gameObject.name == "Yamato(Clone)") {
//					this.gameObject.GetComponent<AttackIowa> ().stopAttack ();
//					gameObject.GetComponent<NavMeshAgent> ().Resume ();
//				} else if (this.gameObject.name == "Kagero" || this.gameObject.name == "Kagero(Clone)") {
//					this.gameObject.GetComponent<AttackDestroyer> ().stopAttack ();
//					gameObject.GetComponent<NavMeshAgent> ().Resume ();
//				} else if (this.gameObject.name == "Mogami" || this.gameObject.name == "Mogami(Clone)") {
//					this.gameObject.GetComponent<AttackCruiser> ().stopAttack ();
//					gameObject.GetComponent<NavMeshAgent> ().Resume ();
//				}
//				Debug.Log ("bisa");
//				CekPosisiMusuh = false;
//			}


//			if (cekPosisiMusuhIowa == true) {
//				gameObject.GetComponent<NavMeshAgent> ().Stop ();
//				Quaternion targetrotation = Quaternion.LookRotation (EnemyCollider.transform.position - transform.position);
//				float str = Mathf.Min (strength * Time.deltaTime, 1);
//				transform.rotation = Quaternion.Lerp (transform.rotation, targetrotation, str);
//				//transform.LookAt (EnemyCollider.transform);
//				//StartCoroutine("MulaiAttackIowa");
//				//this.gameObject.GetComponent<AttackIowa> ().StartAttack ();
//			} else if (cekPosisiMusuhBaltimore == true) {
//				gameObject.GetComponent<NavMeshAgent> ().Stop ();
//				Quaternion targetrotation = Quaternion.LookRotation (EnemyCollider.transform.position - transform.position);
//				float str = Mathf.Min (strength * Time.deltaTime, 1);
//				transform.rotation = Quaternion.Lerp (transform.rotation, targetrotation, str);
//				//transform.LookAt (EnemyCollider.transform);
//				//StartCoroutine("MulaiAttackIowa");
//				//this.gameObject.GetComponent<AttackCruiser> ().StartAttack ();
//			} else if (cekPosisiMusuhBenson == true) {
//				gameObject.GetComponent<NavMeshAgent> ().Stop ();
//				Quaternion targetrotation = Quaternion.LookRotation (EnemyCollider.transform.position - transform.position);
//				float str = Mathf.Min (strength * Time.deltaTime, 1);
//				transform.rotation = Quaternion.Lerp (transform.rotation, targetrotation, str);
//				//transform.LookAt (EnemyCollider.transform);
//				//StartCoroutine("MulaiAttackIowa");
//				//this.gameObject.GetComponent<AttackDestroyer> ().StartAttack ();
//			}
        }
        //Debug.Log (target);
    }