Beispiel #1
0
        private void RemovePlaceableFromList(ThinkingPlaceable p)
        {
            allThinkingPlaceables.Remove(p);

            if (p.faction == Placeable.Faction.Player)
            {
                allPlayers.Remove(p);

                if (p.pType == Placeable.PlaceableType.Unit)
                {
                    playerUnits.Remove(p);
                }
                else
                {
                    playerBuildings.Remove(p);
                }
            }
            else if (p.faction == Placeable.Faction.Opponent)
            {
                allOpponents.Remove(p);

                if (p.pType == Placeable.PlaceableType.Unit)
                {
                    opponentUnits.Remove(p);
                }
                else
                {
                    opponentBuildings.Remove(p);
                }
            }
            else
            {
                Debug.LogError("Error in removing a Placeable from one of the player/opponent lists");
            }
        }
Beispiel #2
0
        private void AddPlaceableToList(ThinkingPlaceable p)
        {
            allThinkingPlaceables.Add(p);

            if (p.faction == Placeable.Faction.Player)
            {
                allPlayers.Add(p);

                if (p.pType == Placeable.PlaceableType.Unit)
                {
                    playerUnits.Add(p);
                }
                else
                {
                    playerBuildings.Add(p);
                }
            }
            else if (p.faction == Placeable.Faction.Opponent)
            {
                allOpponents.Add(p);

                if (p.pType == Placeable.PlaceableType.Unit)
                {
                    opponentUnits.Add(p);
                }
                else
                {
                    opponentBuildings.Add(p);
                }
            }
            else
            {
                Debug.LogError("Error in adding a Placeable in one of the player/opponent lists");
            }
        }
Beispiel #3
0
 private void OnPlaceableDealtDamage(ThinkingPlaceable p)
 {
     if (p.target.state != ThinkingPlaceable.States.Dead)
     {
         float newHealth = p.target.SufferDamage(p.damage);
         p.target.healthBar.SetHealth(newHealth);
     }
 }
        public void AddHealthUI(ThinkingPlaceable p)
        {
            GameObject newUIObject = Instantiate(healthBarPrefab, Vector3.zero, Quaternion.identity,
                                                 healthBarContainer);

            p.healthBar = newUIObject.GetComponent <HealthBar>();
            p.healthBar.Initialize(p);
            p.healthBar.Move(mainCamera);


            healthBars.Add(p.healthBar);
        }
Beispiel #5
0
        private void OnProjectileFired(ThinkingPlaceable p)
        {
            Vector3 adjTargetPos = p.target.transform.position;

            adjTargetPos.y = 1.5f;
            Quaternion rot  = Quaternion.LookRotation(adjTargetPos - p.projectileSpawnPoint.position);
            Projectile proj = GameObject
                              .Instantiate <GameObject>(p.projectilePrefab, p.projectileSpawnPoint.position, rot)
                              .GetComponent <Projectile>();

            proj.target = p.target;
            proj.damage = p.damage;
            allProjectiles.Add(proj);
        }
        public void Initialize(ThinkingPlaceable p)
        {
            originHP = currentHP = p.hitPoints;

            transformToFollow = p.transform;

            bar.GetComponent <Image>().color = (p.faction == Placeable.Faction.Player) ? red : blue;

            wholeWidget.transform.localPosition = new Vector3(0f,
                                                              (p.pType == Placeable.PlaceableType.Unit) ? 3f : 6f,
                                                              (p.pType == Placeable.PlaceableType.Unit) ? 0f : -2f);

            wholeWidget.SetActive(false);
        }
Beispiel #7
0
        private bool FindClosesInList(Vector3 p, List <ThinkingPlaceable> list, out ThinkingPlaceable t)
        {
            t = null;
            bool  targetFound        = false;
            float closestDistanceSqr = Mathf.Infinity;

            for (int i = 0; i < list.Count; i++)
            {
                float sqrDistance = (p - list[i].transform.position).sqrMagnitude;
                if (sqrDistance < closestDistanceSqr)
                {
                    t = list[i];
                    closestDistanceSqr = sqrDistance;
                    targetFound        = true;
                }
            }

            return(targetFound);
        }
Beispiel #8
0
        private IEnumerator Dispose(ThinkingPlaceable p)
        {
            yield return(new WaitForSeconds(3f));

            Destroy(p.gameObject);
        }
 public virtual void SetTarget(ThinkingPlaceable t)
 {
     target   = t;
     t.OnDie += TargetIsDead;
 }
 public void RemoveHealthUI(ThinkingPlaceable p)
 {
     healthBars.Remove(p.healthBar);
     Destroy(p.healthBar.gameObject);
 }