//public float floorOffset = 1;
    //public float speed = 10;
    //public float stopDistanceOffset = 0.5f;
    //private Vector3 moveToDest = Vector3.zero;

    // Use this for initialization


    // Update is called once per frame
    void Update()
    {
        if (GetComponent <Renderer> ().isVisible&& Input.GetMouseButton(0))
        {
            if (!selectedByClick)
            {
                Vector3 camPos = Camera.main.WorldToScreenPoint(transform.position);
                camPos.y = CameraOperator2.InverMouseY(camPos.y);
                selected = CameraOperator2.selection.Contains(camPos);
            }
            if (selected && projector == null)
            {
                projector = (GameObject)GameObject.Instantiate(selectionProjector);
                projector.transform.parent        = transform;
                projector.transform.localPosition = new Vector3(0, 38, 0);
            }
            else if (!selected && projector != null)
            {
                GameObject.Destroy(projector);
                projector = null;
            }
        }
        if (selected && Input.GetMouseButtonUp(1))
        {
            Vector3 destination = CameraOperatorPesawat.GetDestination();
            if (destination != Vector3.zero)
            {
                gameObject.GetComponent <NavMeshAgent> ().SetDestination(destination);
                //Quaternion.FromToRotation(Vector3.zero, destination);
                //moveToDest = destination;
                //moveToDest.y += floorOffset;
            }
        }
        //UpdateMove ();
    }
예제 #2
0
    void Update()
    {
        if (GetComponent <Renderer> ().isVisible&& Input.GetMouseButton(0))
        {
            if (!selectedByClick)
            {
                Vector3 camPos = Camera.main.WorldToScreenPoint(transform.position);
                camPos.y = CameraOperator2.InverMouseY(camPos.y);
                selected = CameraOperator2.selection.Contains(camPos);
            }

            //{
            if (selected && projector == null)
            {
                projector = (GameObject)GameObject.Instantiate(selectionProjector);
                projector.transform.parent        = transform;
                projector.transform.localPosition = new Vector3(0, 1, 0);
            }
            //if (!EventSystem.current.IsPointerOverGameObject ()) {
            if (!selected && projector != null)
            {
                GameObject.Destroy(projector);
                projector = null;
            }
            //}
        }
    }
    // 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);
    }
예제 #4
0
    //public Vector3 target;


    void Start()
    {
        camShot        = GameObject.Find("CameraController").transform.FindChild("RTSCamera").GetComponent <CameraOperator2>();
        random         = new Random();
        targetPosition = transform.position;
        //	_agentHandler = Simulator.Instance.addAgent(transform.position, agentHeight, neighborDist, maxNeighbors, timeHorizon, timeHorizonObst, radius, maxSpeed, Vector2.zero, isKinematic);
//		simulatorbefore = GameObject.Find ("Simulator(Clone)");
//		//Simulator.Instance.Clear ();
//		Destroy (simulatorbefore.gameObject);
//		Simulator.Instance.Clear ();
//		Instantiate (SimulatorGameObject);
        _agentHandler = Simulator.Instance.addAgent(transform.position, agentHeight, neighborDist, maxNeighbors, timeHorizon, timeHorizonObst, radius, maxSpeed, Vector2.zero, isKinematic);
    }
예제 #5
0
    //public GameObject button = null;


    //public float floorOffset = 1;
    //public float speed = 10;
    //public float stopDistanceOffset = 0.5f;
    //private Vector3 moveToDest = Vector3.zero;

    // Use this for initialization


    // Update is called once per frame
    void Update()
    {
        GameObject Canvas    = GameObject.Find("Canvas");
        GameObject PanelUnit = Canvas.transform.GetChild(2).gameObject;
        GameObject Panel     = PanelUnit.transform.GetChild(0).gameObject;
        //GameObject panel = Canvas.transform.GetChild (0).gameObject;
        GameObject Text             = Panel.transform.GetChild(0).gameObject;
        GameObject ButtonBattleship = Panel.transform.GetChild(1).gameObject;
        GameObject ButtonCruiser    = Panel.transform.GetChild(2).gameObject;
        GameObject ButtonDestroyer  = Panel.transform.GetChild(3).gameObject;

        if (GetComponent <Renderer> ().isVisible&& Input.GetMouseButton(0))
        {
            if (!selectedByClick)
            {
                Vector3 camPos = Camera.main.WorldToScreenPoint(transform.position);
                camPos.y = CameraOperator2.InverMouseY(camPos.y);
                selected = CameraOperator2.selection.Contains(camPos);
            }

            //{
            if (selected && projector == null)
            {
                projector = (GameObject)GameObject.Instantiate(selectionProjector);
                projector.transform.parent        = transform;
                projector.transform.localPosition = new Vector3(0, 36, 0);
                ButtonBattleship.SetActive(true);
                ButtonCruiser.SetActive(true);
                ButtonDestroyer.SetActive(true);
                Text.SetActive(true);
            }
            if (!EventSystem.current.IsPointerOverGameObject())
            {
                if (!selected && projector != null)
                {
                    GameObject.Destroy(projector);
                    projector = null;
                    ButtonBattleship.SetActive(false);
                    ButtonCruiser.SetActive(false);
                    ButtonDestroyer.SetActive(false);
                    Text.SetActive(false);
                    //GameObject.Find ("Canvas/PanelProgress").SetActive (false);
                }
            }
        }
    }
예제 #6
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);
    }