Пример #1
0
    IEnumerator Explode()
    {
        RaycastHit[] hitinfo = Physics.SphereCastAll(transform.position, 50, Vector3.forward, 50, int.MaxValue, QueryTriggerInteraction.UseGlobal);
        foreach (RaycastHit hit1 in hitinfo)
        {
            //If it hits a body of a unit the script continues
            if (hit1.collider.tag == "BodyPart")
            {
                ///Calculates the damage depending on the distance between the explosion and the target
                fractionalDistance = (Mathf.Max(0, 75 - Vector3.Distance(transform.position, hit1.transform.position))) / 75;
                damage             = scaledDamage * fractionalDistance + minimumDamage;
                target             = hit1.transform.GetComponentInParent <OffensivePlaceables>();
                ///Also gets the target's script so it can deal damage

                //checks if the target is an enemy and if so deals damage
                if (target != null && target.currentTeam != currentTeam)
                {
                    enemyUnits.Add(target);
                    target = enemyUnits[0];
                    target.DealDamage(damage);
                    enemyUnits.RemoveAt(0);
                }
            }
        }
        //Waits three seconds until the patricle effect has fully stopped, and then destroys itself.
        yield return(new WaitForSeconds(3f));

        Destroy(gameObject);
    }
Пример #2
0
    public void OnTriggerStay(Collider other)
    {
        if (other.tag == "BodyPart")
        {
            targets = other.GetComponentsInParent <OffensivePlaceables>();
        }

        //Getting the enemy
        if (targets != null)
        {
            for (int i = 0; i < targets.Length; i++)
            {
                if (targets[i].currentTeam != offensivePlaceablesRef.currentTeam)
                {
                    enemy = targets[i];
                }
            }

            //Checking whether or not to attack
            if (enemy != null)
            {
                attackReady = true;
            }

            if (enemy == null)
            {
                attackReady = false;
            }
        }
    }
Пример #3
0
    public void OnTriggerExit(Collider other)
    {
        OffensivePlaceables target = null;

        if (other.tag == "CheckForEnemy")
        {
            target = other.GetComponent <OffensivePlaceables>();
        }

        if (target != null && offensivePlaceablesRef.currentTeam == target.currentTeam)
        {
            units.Remove(target);
            offensivePlaceablesRef.moveToTarget = false;
            target = null;
        }
    }
Пример #4
0
    void OnTriggerEnter(Collider other)
    {
        if (other.tag == "BodyPart")
        {
            targets = other.GetComponentsInParent <OffensivePlaceables>();
        }

        if (targets != null)
        {
            for (int i = 0; i < targets.Length; i++)
            {
                if (targets[i].currentTeam == offensivePlaceablesRef.currentTeam)
                {
                    units.Add(targets[i]);
                    unit = units[0];
                }
            }
            offensivePlaceablesRef.moveToTarget = true;
            offensivePlaceablesRef.target       = units[units.Count - 1];
        }
    }
Пример #5
0
 private void Start()
 //Reference to the unit and the arrow's starting velocity
 {
     myUnit   = GetComponentInParent <OffensivePlaceables>();
     velocity = new Vector3(0, 1, 20);
 }
Пример #6
0
 //Getting variable
 void Start()
 {
     offensivePlaceablesRef = GetComponentInParent <OffensivePlaceables>();
 }
Пример #7
0
 private void Start()
 {
     offensivePlaceablesRef = GetComponentInParent <OffensivePlaceables>();
     StartCoroutine(Heal());
 }
Пример #8
0
    void Update()
    {
        if (agent != null && agent.isOnNavMesh)
        {
            float dist = agent.remainingDistance;

            if (dist != Mathf.Infinity && agent.pathStatus == NavMeshPathStatus.PathComplete && dist - agent.stoppingDistance <= 0)
            {
                offensivePlaceablesRef.moveToTarget = true;
            }
            else
            {
                offensivePlaceablesRef.moveToTarget = false;
            }
        }

        if (Input.GetMouseButtonDown(0))
        {
            foreach (GameObject selectObjects in selectableObjects)
            {
                clearSelection();
            }
        }

        if (Input.GetMouseButtonDown(1))
        {
            foreach (GameObject unit in selectedObjects)
            {
                offensivePlaceablesRef = unit.GetComponent <OffensivePlaceables>();
                offensivePlaceablesRef.moveToTarget = false;
                agent       = unit.GetComponent <NavMeshAgent>();
                agent.speed = 50;
                agent.SetDestination(GetPointUnderCursor());
            }
        }

        //Shoots a ray and if it hits a unit makes the unit selected
        if (Input.GetMouseButtonDown(0))
        {
            mousePos1 = Camera.main.ScreenToViewportPoint(Input.mousePosition);

            RaycastHit rayHit;

            if (Physics.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition), out rayHit, Mathf.Infinity, clickablesLayer, QueryTriggerInteraction.Collide))
            {
                ClickOn clickOnScript = rayHit.collider.GetComponent <ClickOn>();

                if (clickOnScript != null)
                {
                    if (Input.GetKey("left ctrl"))
                    {
                        if (clickOnScript.currentlySelected == false)
                        {
                            selectedObjects.Add(rayHit.collider.gameObject);
                            clickOnScript.currentlySelected = true;
                            clickOnScript.ClickMe();
                        }
                        else
                        {
                            selectedObjects.Remove(rayHit.collider.gameObject);
                            clickOnScript.currentlySelected = false;
                            clickOnScript.ClickMe();
                        }
                    }
                    else
                    {
                        clearSelection();

                        selectedObjects.Add(rayHit.collider.gameObject);
                        clickOnScript.currentlySelected = true;
                        clickOnScript.ClickMe();
                    }
                }
            }
        }

        if (Input.GetMouseButtonUp(0))
        {
            mousePos2 = Camera.main.ScreenToViewportPoint(Input.mousePosition);

            if (mousePos1 != mousePos2)
            {
                SelectObjects();
            }
        }
    }