示例#1
0
//	void Update ()
//	{
//		if (!scouting) {
//			mapScript.ClearScoutedTiles();
//			if (target) {
//				dampTime = 0.15f;
//				Vector3 point = GetComponent<Camera> ().WorldToViewportPoint (target.position);
//				Vector3 delta = target.position - GetComponent<Camera> ().ViewportToWorldPoint (new Vector3 (0.5f, 0.5f, point.z)); //(new Vector3(0.5, 0.5, point.z));
//				Vector3 destination = transform.position + delta;
//				transform.position = Vector3.SmoothDamp (transform.position, destination, ref velocity, dampTime);
//			} else {
//				target = GameObject.FindGameObjectWithTag ("Map_Manager").GetComponent<Transform> ();
//			}
//		} else {
//
//		}
//
//	}
//
    public void ScoutCam(Vector3 mousePos)
    {
        dampTime = 1f;
        Vector3 point       = GetComponent <Camera> ().WorldToViewportPoint(mousePos);
        Vector3 delta       = mousePos - GetComponent <Camera> ().ViewportToWorldPoint(new Vector3(0.5f, 0.5f, point.z));    //(new Vector3(0.5, 0.5, point.z));
        Vector3 destination = transform.position + delta;

        transform.position = Vector3.SmoothDamp(transform.position, destination, ref velocity, dampTime);

        mapScript.SpawnTilesForScout(mousePos);
    }
示例#2
0
    void Select()
    {
        Vector3 m = Camera.main.ScreenToWorldPoint(Input.mousePosition);
//		Vector3 camPos = Camera.main.transform.position;
        RaycastHit2D hit = Physics2D.Raycast(new Vector2(m.x, m.y), -Vector2.up);

//		RaycastHit2D hit = Physics2D.Linecast (new Vector2 (m.x, m.y), -Vector2.up);
        if (hit.collider != null)
        {
            if (hit.collider.CompareTag("Captain"))
            {
                if (Input.GetMouseButtonDown(0))
                {
                    print("You clicked on Captain.");
                    selectedUnit = hit.collider.gameObject;                     // this stores the selected unit as a GameObject

                    // Instantiate a Selection Box at that Unit's position
                    if (mySBox == null)
                    {
                        mySBox = Instantiate(selectionBox, selectedUnit.transform.position, Quaternion.identity) as GameObject;
                        mySBox.transform.parent = selectedUnit.transform;
                        // sets the Selection box parent to be the Unit so it can follow it around if Moved
                    }
                    else
                    {
                        Destroy(mySBox);                          // Destroy the old one, bring in the new selection
                        mySBox = Instantiate(selectionBox, selectedUnit.transform.position, Quaternion.identity) as GameObject;
                        mySBox.transform.parent = selectedUnit.transform;
                    }
                }
            }
            else if (hit.collider.CompareTag("Tile") || hit.collider.CompareTag("Destroyed Town") || hit.collider.CompareTag("Depleted") || hit.collider.CompareTag("Food Source"))
            {
                // if you click on a town tile, watch where the mouse position is when player lets it go to move there
                // mouse is not busy, meaning not currently shooting or placing units
                mouseIsBusy = false;

                if (Input.GetMouseButtonUp(0) && !mouseIsBusy)
                {
                    print("You clicked on a tile");
                    Vector2 mouseRounded = new Vector2(Mathf.Round(m.x), Mathf.Round(m.y));
                    Vector2 myPosRounded = new Vector2(Mathf.Round(myTransform.position.x), Mathf.Round(myTransform.position.y));
//
//					if (mouseRounded.x == myPosRounded.x - 1 && mouseRounded.y == myPosRounded.y) { // left
//						//ADD & clear the resource tile under new town tile
//						mapScript.SpawnTilesByExpanding(mouseRounded);
//					} else if (mouseRounded.x == myPosRounded.x + 1 && mouseRounded.y == myPosRounded.y) { // right
//						//ADD & clear the resource tile under new town tile
//						mapScript.SpawnTilesByExpanding(mouseRounded);
//					} else if (mouseRounded.y == myPosRounded.y + 1 && mouseRounded.x == myPosRounded.x) { // up
//						//ADD & clear the resource tile under new town tile
//						mapScript.SpawnTilesByExpanding(mouseRounded);
//					} else if (mouseRounded.y == myPosRounded.y - 1 && mouseRounded.x == myPosRounded.x) { // down
//						//ADD & clear the resource tile under new town tile
//						mapScript.SpawnTilesByExpanding(mouseRounded);
//					}

                    // vvvvvv THIS CODE BELOW ACTUALLY MOVES THE GAMEOBJECT WITH THIS SCRIPT WHEN EXPANDING vvvv

                    //Vector2 myPosRounded = new Vector2 (Mathf.Round (myTransform.position.x), Mathf.Round (myTransform.position.y));
//					if (mouseRounded.x < myPosRounded.x && mouseRounded.y < myPosRounded.y + 1 && mouseRounded.y > myPosRounded.y - 1) { // left
//						myTransform.position = new Vector3 (myTransform.position.x - 1, myTransform.position.y, 0);
//					} else if (mouseRounded.x > myPosRounded.x && mouseRounded.y < myPosRounded.y + 1 && mouseRounded.y > myPosRounded.y - 1) { // right
//						myTransform.position = new Vector3 (myTransform.position.x + 1, myTransform.position.y, 0);
//					} else if (mouseRounded.y > myPosRounded.y && mouseRounded.x < myPosRounded.x + 1 && mouseRounded.x > myPosRounded.x - 1) { // up
//						myTransform.position = new Vector3 (myTransform.position.x, myTransform.position.y + 1, 0);
//					} else if (mouseRounded.y < myPosRounded.y && mouseRounded.x < myPosRounded.x + 1 && mouseRounded.x > myPosRounded.x - 1) { // up
//						myTransform.position = new Vector3 (myTransform.position.x, myTransform.position.y - 1, 0); // down
//					}
                }
            }
            else if (hit.collider.CompareTag("Gatherer"))
            {
                mouseIsBusy = true;
            }
            else if (hit.collider.CompareTag("UI"))
            {
                mouseIsBusy = true;
            }
        }
        else             // hit.collider is null so mouse is definitely busy
        {
            mouseIsBusy = false;
        }

        // vvv BATTLEVIEW VVVV
        // for dragging the unit with mouse
        if (selectedUnit != null)           // once you click on a unit this will be true
        {
            if (Input.GetMouseButton(0) && !gmScript.battleStarted)
            {
                Vector3 followMousePosition = new Vector3(m.x, m.y, 0);
                selectedUnit.transform.position = followMousePosition;
            }
            else
            {
                selectedUnit = null;
            }
        }

        //Controls for Scout function (ability to look around the map) //TODO: Add finite ammount of scouting time
        if (Input.GetMouseButton(1))
        {
            camFollowScript.scouting = true;
            camFollowScript.ScoutCam(m);
            mapScript.SpawnTilesForScout(m);
        }
        else
        {
            camFollowScript.scouting = false;
            mapScript.ClearScoutedTiles();
        }
    }