Example #1
0
        public void Update(int filterIndex, Selection selection, float deltaTime)
        {
            foreach (var s in selection)
            {
                C_TowerAttack c = s.GetComp <C_TowerAttack>();

                Entity target = s.GetComp <C_Target>().TargetAsEntity(selection.context);

                //UnityEngine.Debug.LogError("Entity.IsNullOrInvalid(target) =" + Entity.IsNullOrInvalid(target));
                if (!Entity.IsNullOrInvalid(target))
                {
                    c.timer += deltaTime;

                    if (c.timer > c.preAttack)
                    {
                        c.timer -= (c.preAttack + c.postAttack);
                        Entity bullet = selection.context.Create(c.bulletRecipe);
                        bullet.SetPosition(s.GetPosition());
                        bullet.GetComp <C_TargetPos>().targetPos = target.GetPosition();
                        bullet.GetComp <C_Target>().target       = s.GetComp <C_Target>().target;
                    }
                }
                else
                {
                    c.timer = 0;
                }
            }
        }
Example #2
0
        public void Setup(Entity e, Context context)
        {
            e.AddComp <C_Position>();
            e.AddComp <C_Rotation>();

            TowerEntry towerEntry = e.GetComp <C_TowerConfig>().cfg;

            C_Asset asset = e.AddComp <C_Asset>();

            asset.mesh     = "Mesh/TowerTest"; // towerEntry.asset;
            asset.material = "Materials/Blue";

            e.AddComp <C_Renderer>();


            var findTarget = e.AddComp <C_TowerFindTarget>();

            findTarget.range = towerEntry.range / 100f;
            e.AddComp <C_TowerFindTargetGizmos>();


            C_TowerAttack attack = e.AddComp <C_TowerAttack>();

            attack.timer      = 0;
            attack.preAttack  = towerEntry.postAttack;
            attack.postAttack = towerEntry.postAttack;

            e.AddComp <C_Target>();
        }