Esempio n. 1
0
 private void seleccionarUnidades()
 {
     Collider2D[] colliders = Physics2D.OverlapAreaAll(startPosition, position());
     foreach (Collider2D collider2D in colliders)
     {
         //      Debug.Log(collider2D.name);
         UnitRTS unitRts = collider2D.GetComponent <UnitRTS>();
         if (unitRts != null)
         {
             unitRts.SetSeletedVisible(true);
             unitsList.Add(unitRts);
         }
     }
     //  Debug.Log(unitsList.Count);
 }
Esempio n. 2
0
    // Update is called once per frame
    void Update()
    {
        if (Input.GetMouseButtonDown(0))
        {
            selectionAreaTransform.gameObject.SetActive(true);
            startPoistion = UtilsClass.GetMouseWorldPosition();
        }

        if (Input.GetMouseButton(0))
        {
            var mouseWorldPosition = UtilsClass.GetMouseWorldPosition();
            var lowerLeft          = new Vector3(Mathf.Min(startPoistion.x, mouseWorldPosition.x),
                                                 Mathf.Min(startPoistion.y, mouseWorldPosition.y));
            var upperRight = new Vector3(Mathf.Max(startPoistion.x, mouseWorldPosition.x), Mathf.Max(startPoistion.y, mouseWorldPosition.y));
            selectionAreaTransform.position   = lowerLeft;
            selectionAreaTransform.localScale = upperRight - lowerLeft;
        }

        if (Input.GetMouseButtonUp(0))
        {
            selectionAreaTransform.gameObject.SetActive(false);

            Collider2D[] collider2DArray = Physics2D.OverlapAreaAll(startPoistion, UtilsClass.GetMouseWorldPosition());
            Debug.Log("#####");


            foreach (UnitRTS unitRts in SelectedUnitRTSList)
            {
                unitRts.SetSelectedVisible(false);
            }
            SelectedUnitRTSList.Clear();

            foreach (Collider2D collider2D1 in collider2DArray)
            {
                UnitRTS unitRts = collider2D1.GetComponent <UnitRTS>();
                if (unitRts != null)
                {
                    unitRts.SetSelectedVisible(true);
                    SelectedUnitRTSList.Add(unitRts);
                }
            }

            Debug.Log(SelectedUnitRTSList.Count);
        }
    }
Esempio n. 3
0
    public void Damage(UnitRTS unitRTS, int damageAmount)
    {
        healthSystem.Damage(damageAmount);

        Vector3 bloodDir = (GetPosition() - unitRTS.GetPosition()).normalized;

        Blood_Handler.SpawnBlood(GetPosition(), bloodDir);

        DamagePopup.Create(GetPosition(), damageAmount, false);
        healthSystem.Damage(damageAmount);
        if (healthSystem.IsDead())
        {
            FlyingBody.Create(GameAssets.i.pfEnemyFlyingBody, GetPosition(), bloodDir);
            Destroy(gameObject);
        }
        else
        {
            // Knockback
            //transform.position += bloodDir * 5f;
        }
    }
Esempio n. 4
0
    private void Update()
    {
        if (Input.GetMouseButtonDown(0))
        {
            // Left Mouse Button Pressed
            selectionAreaTransform.gameObject.SetActive(true);
            startPosition = UtilsClass.GetMouseWorldPosition();
        }

        if (Input.GetMouseButton(0))
        {
            // Left Mouse Button Held Down
            Vector3 currentMousePosition = UtilsClass.GetMouseWorldPosition();
            Vector3 lowerLeft            = new Vector3(
                Mathf.Min(startPosition.x, currentMousePosition.x),
                Mathf.Min(startPosition.y, currentMousePosition.y)
                );
            Vector3 upperRight = new Vector3(
                Mathf.Max(startPosition.x, currentMousePosition.x),
                Mathf.Max(startPosition.y, currentMousePosition.y)
                );
            selectionAreaTransform.position   = lowerLeft;
            selectionAreaTransform.localScale = upperRight - lowerLeft;
        }

        if (Input.GetMouseButtonUp(0))
        {
            // Left Mouse Button Released
            selectionAreaTransform.gameObject.SetActive(false);

            Collider2D[] collider2DArray = Physics2D.OverlapAreaAll(startPosition, UtilsClass.GetMouseWorldPosition());

            // Deselect all Units
            foreach (UnitRTS unitRTS in selectedUnitRTSList)
            {
                unitRTS.SetSelectedVisible(false);
            }
            selectedUnitRTSList.Clear();

            // Select Units within Selection Area
            foreach (Collider2D collider2D in collider2DArray)
            {
                UnitRTS unitRTS = collider2D.GetComponent <UnitRTS>();
                if (unitRTS != null)
                {
                    unitRTS.SetSelectedVisible(true);
                    selectedUnitRTSList.Add(unitRTS);
                }
            }

            if (selectedUnitRTSList.Count == 0)
            {
                CursorManager.Instance.SetActiveCursorType(CursorManager.CursorType.Arrow);
            }
            else
            {
                CursorManager.Instance.SetActiveCursorType(CursorManager.CursorType.Move);
            }
        }

        if (Input.GetMouseButtonDown(1))
        {
            // Right Mouse Button Pressed
            HandleRightClick();
        }
    }
Esempio n. 5
0
    // Start is called before the first frame update
    private void Awake()
    {
        //Cursor.lockState = CursorLockMode.Confined;
        //Cursor.visible = false;
        int amountOfSomething = Random.Range(2, 4);

        for (int i = 0; i < amountOfSomething; i++)
        {
            for (int a = 0; a < 50; a++)
            {
                float xpos = Random.Range(-35, 35);
                float zpos = Random.Range(-35, 35);
                if (!Physics.CheckCapsule(new Vector3(xpos, 7, zpos), new Vector3(xpos, 10f, zpos), 4))
                {
                    Instantiate(spiderMans, new Vector3(xpos, 1f, zpos), Quaternion.Euler(Quaternion.identity.x, Quaternion.identity.y, Random.Range(-5f, 5f)));
                    break;
                }
            }
        }
        amountOfSomething = Random.Range(15, 30);
        for (int i = 0; i < amountOfSomething; i++)
        {
            for (int a = 0; a < 50; a++)
            {
                float xpos = Random.Range(-45f, 45f);
                float zpos = Random.Range(-45f, 45f);
                if (!Physics.CheckCapsule(new Vector3(xpos, 7, zpos), new Vector3(xpos, 10f, zpos), 4))
                {
                    Instantiate(fakeBush, new Vector3(xpos, 1f, zpos), Quaternion.Euler(Quaternion.identity.x, Random.Range(0f, 360), Quaternion.identity.z));
                    break;
                }
            }
        }
        amountOfSomething = Random.Range(3, 5);
        for (int i = 0; i < amountOfSomething; i++)
        {
            for (int a = 0; a < 50; a++)
            {
                float xpos = Random.Range(-40f, 40);
                float zpos = Random.Range(-40, 40);
                if (!Physics.CheckCapsule(new Vector3(xpos, 7, zpos), new Vector3(xpos, 10f, zpos), 5))
                {
                    Instantiate(rock, new Vector3(xpos, 1f, zpos), Quaternion.Euler(Random.Range(0f, 360f), Random.Range(0f, 360f), Random.Range(0f, 360f)));
                    break;
                }
            }
        }
        amountOfSomething = Random.Range(5, 15);
        for (int i = 0; i < amountOfSomething; i++)
        {
            for (int a = 0; a < 50; a++)
            {
                float xpos = Random.Range(-45f, 45f);
                float zpos = Random.Range(-45f, 45f);
                if (!Physics.CheckCapsule(new Vector3(xpos, 7, zpos), new Vector3(xpos, 10f, zpos), 3))
                {
                    Instantiate(troop, new Vector3(xpos, 1, zpos), Quaternion.identity);
                    break;
                }
            }
        }
        selectedUnitRtsList = new List <UnitRTS>();
        mainCam             = GameObject.FindGameObjectWithTag("MainCamera") /*.GetComponent<Rigidbody>()*/;
        camOriginalPos      = mainCam.transform.position.y;
        //cam = GameObject.FindGameObjectWithTag("MainCamera").GetComponent<Rigidbody>();
        actualCam = GameObject.FindGameObjectWithTag("MainCamera").GetComponent <Camera>();
        NavMeshBuilder.BuildNavMesh();
        allMyUnits = new List <UnitRTS>();
        GameObject[] tempUnit = GameObject.FindGameObjectsWithTag("Troop");
        for (int i = 0; i < tempUnit.Length; i++)
        {
            UnitRTS unitRTS = tempUnit[i].GetComponent <UnitRTS>();
            if (unitRTS != null)
            {
                allMyUnits.Add(unitRTS);
            }
        }
    }