public override void OnEnd(TowerController tower)
 {
     if (tower.defMat != null)
     {
         tower.mesh.sharedMaterial = tower.defMat;
     }
 }
Beispiel #2
0
        // Start is called before the first frame update
        void Start()
        {
            ec = GetComponent <EnemyController>();
            t  = GetComponent <TowerController>();

            if (ec == null && t == null) //if EnemyController and Tower are both null,
            {
                Destroy(gameObject);     //kill itself, it has no valid owner.
            }
            if (ec != null && t != null) //if EnemyController and Tower are both valid,
            {
                Destroy(gameObject);     //kill itself, it cannot have two owners.
            }

            if (ec != null)
            {
                owner            = ec.gameObject;
                isPlayerFirendly = false;
            }
            else if (t != null)
            {
                owner            = t.gameObject;
                isPlayerFirendly = true;
            }
        }
 public override void OnStart(TowerController tower)
 {
     if (tower.frozenMat != null)
     {
         tower.mesh.sharedMaterial = tower.frozenMat;
     }
 }
        // Update is called once per frame
        public override TowerState Update(TowerController tower)
        {
            if (tower.Zap(tower.GetClosestEnemy()) == true)
            {
                switch (tower.currentAttack)
                {
                case TowerController.AttackType.Zap:
                    tower.Zap(tower.GetClosestEnemy());
                    break;

                case TowerController.AttackType.Projectile:
                    tower.Shoot(tower.GetClosestEnemy());
                    break;

                case TowerController.AttackType.Ice:
                    tower.Freeze(tower.GetClosestEnemy());
                    break;

                default:
                    break;
                }

                return(new TowerStateIdle());
            }
            else
            {
                return(new TowerStateSearch());
            }
        }
Beispiel #5
0
 // Update is called once per frame
 public override TowerState Update(TowerController tower)
 {
     tower.atkTimer += Time.deltaTime;
     if (tower.atkTimer >= tower.attackSpeed)
     {
         return(new TowerStateSearch());
     }
     return(null);
 }
        // Update is called once per frame
        public override TowerState Update(TowerController tower)
        {
            tower.frozenTimer += Time.deltaTime;
            if (tower.frozenTimer >= tower.freezeDuration)
            {
                tower.isFrozen    = false;
                tower.frozenTimer = 0;
                return(tower.previousState);
            }

            return(null);
        }
Beispiel #7
0
        // Update is called once per frame
        public override TowerState Update(TowerController tower)
        {
            if (tower.GetClosestEnemy() != null)
            {
                Debug.Log("target locked");

                tower.atkTimer = 0;

                return(new TowerStateAttack());
            }
            else
            {
                Debug.Log("No enemy");
            }
            return(null);
        }
Beispiel #8
0
        void OnTriggerEnter(Collider collider)
        {
            print("something entered my trigger...");

            EnemyController e = collider.GetComponent <EnemyController>();

            if (e != null)
            {
                enemyControllers.Add(e);
            }

            TowerController t = collider.GetComponent <TowerController>();

            if (t != null)
            {
                towers.Add(t);
            }
        }
Beispiel #9
0
        TowerController GetClosestTower()
        {
            TowerController result = null;
            float           minDis = 0;

            // find closest
            foreach (TowerController t in towers)
            {
                float dis = (t.transform.position - transform.position).magnitude; // distance from tower to enemy
                if (dis < minDis || result == null)
                {
                    result = t;
                    minDis = dis;
                }
            }
            if (minDis <= freezeRange)
            {
                atkMode = true;
            }
            return(result);
        }
        private void SpawnTowerOnRightClick()
        {
            if (Input.GetButtonDown("Fire2")) // on click:
            {
                GridCoords grid = CoordsWorldToGrid(gridHelper.position);


                if (IsValidGridCoords(grid))
                {
                    TowerController existingTower = LookupTower(grid);

                    if (existingTower == null)
                    {
                        // CHECK AI NAVIGATION PATHS
                        if (currentTowerToBuy != null)
                        {
                            TowerController tower = Instantiate(currentTowerToBuy, gridHelper.position, Quaternion.identity);
                            towers[grid.x, grid.y] = tower;
                        }
                    }
                }
            }
        }
        // Update is called once per frame
        void Update()
        {
            /*
             * if (Input.GetButtonDown("Fire1")) // on click:
             * {
             *  Ray ray = cam.ScreenPointToRay(Input.mousePosition); // create a ray from the camera, throught the mouse position
             *
             *  if (Physics.Raycast(ray, out RaycastHit hit)) // shoot ray into scene, detect hit
             *  {
             *
             *      Instantiate(enemyPrefab, hit.point, Quaternion.identity);
             *
             *  }
             *
             *
             * }
             */
            SetHelperToMouse();
            SpawnTowerOnRightClick();

            if (Input.GetButtonDown("Fire1"))                                               // on left click:
            {
                Ray ray = cam.ScreenPointToRay(Input.mousePosition);                        // create a ray from the camera, throught the mouse position

                if (Physics.Raycast(ray, out RaycastHit hit, 50, objectsThatSupportTowers)) // shoot ray into scene, detect hit
                {
                    TowerController tower = hit.collider.GetComponentInParent <TowerController>();
                    if (tower != null)
                    {
                        //if (currentlySelectedTower != null) currentlySelectedTower.EndSelect();
                        currentlySelectedTower = tower;
                        //currentlySelectedTower.StartSelect();
                    }
                }
            }
        }
Beispiel #12
0
 public virtual void OnEnd(TowerController tower)
 {
 }
Beispiel #13
0
 public virtual void OnStart(TowerController tower)
 {
 }
Beispiel #14
0
 // Update is called once per frame
 public abstract TowerState Update(TowerController tower);