示例#1
0
    // Update is called once per frame
    void Update()
    {
        if (GetComponent <Renderer>().isVisible&& Input.GetMouseButton(0))
        {
            Vector3 camPos = Camera.main.WorldToScreenPoint(transform.position);
            camPos.y = CameraOperator.InvertMouseY(camPos.y);
            selected = CameraOperator.selection.Contains(camPos);

            if (selected)
            {
                GetComponent <Renderer>().material.color = Color.red;
            }
            else
            {
                GetComponent <Renderer>().material.color = Color.white;
            }
        }

        if (selected && Input.GetMouseButtonUp(1))
        {
            Vector3 destination = CameraOperator.GetDestination();

            if (destination != Vector3.zero)
            {
                moveToDest    = destination;
                moveToDest.y += floorOffset;
            }
        }

        UpdateMove();
    }
示例#2
0
    void Update()
    {
        if (speed < 0)
        {
            speed = 0;
        }
        if (isAlive)
        {
            if (hp < 1)
            {
                if (selected)
                {
                    unitManager.GetComponent <UnitManager>().DeselectUnit(this.gameObject);
                }
                Instantiate(deathExplosionFX, transform.position, transform.rotation);
                foreach (Transform child in transform)
                {
                    child.SendMessage("Deactivate");
                }
                transform.DetachChildren();
                isAlive = false;
                Destroy(this.gameObject);
            }
            //Debug.Log(selectedList);
            if (GetComponent <Renderer>().isVisible&& Input.GetMouseButton(0)) //Detect if unit is in view and select by dragging
            {
                if (!selectedByClick)
                {
                    Vector3 camPos = Camera.main.WorldToScreenPoint(transform.position);
                    camPos.y = CameraOperator.InvertMouseY(camPos.y);
                    selected = CameraOperator.selection.Contains(camPos);
                }
                if (selected)
                {
                    GetComponent <Renderer>().material.color = Color.red;
                    if (selectedList == false)
                    {
                        if (PlayerPrefs.GetInt("EditorMode") == 0)
                        {
                            unitManager.GetComponent <UnitManager>().SelectAdditionalUnit(this.gameObject);
                        }
                        selectionCircle.GetComponent <SpriteRenderer>().enabled = true;
                        selectedList = true;
                    }
                }
                else
                {
                    if (selectedList == true)//Deselect units
                    {
                        if (PlayerPrefs.GetInt("EditorMode") == 0)
                        {
                            unitManager.GetComponent <UnitManager>().DeselectAllUnits();
                        }
                        selectionCircle.GetComponent <SpriteRenderer>().enabled = false;
                        selectedList = false;
                    }
                    GetComponent <Renderer>().material.color = originalColor;
                }
            }
            if (selected && Input.GetMouseButtonUp(1))//Move script
            {
                if (PlayerPrefs.GetInt("EditorMode") == 0)
                {
                    unitManager.GetComponent <UnitManager>().DestOffset();
                }
                //Vector3 destination = CameraOperator.GetDestination();

                /*if(destination != Vector3.zero)
                 * {
                 *  //gameObject.GetComponent<NavMeshAgent>().SetDestination(destination); //Unity Pro
                 * // moveToDest = destination;
                 *  //moveToDest.y += floorOffset;
                 * }*/
            }

            UpdateMove();
            if (hasTarget && target == null)
            {
                hasTarget = false;
            }
        }
    }