/// <summary> /// Overrides the towers's update function to use to attack the targeted base /// </summary> /// <param name="tower">stores a reference of the TowerStateMachine in tower</param> /// <returns>>It returns back into itself until the current enemy is destroyed</returns> public override TowerState Update(TowerStateMachine tower) { if (tower.attackTarget != null) // if the attackTarget isn't null { tower.timeUntilNextShot -= Time.deltaTime; // then start attack timer if (tower.timeUntilNextShot <= 0) // if atack timer reaches zero { tower.ShootProjectile(); // shoot tower.timeUntilNextShot = tower.timeBetweenShots; // reset timer } } return(null); // return back into itself }
/// <summary> /// Handles when a tower is selected, doesn't work anymore /// </summary> private void ClickToSelectTower() { if (Input.GetButtonDown("Fire1") && Input.GetButton("Jump")) // on left click + spacebar { Ray ray = cam.ScreenPointToRay(Input.mousePosition); // create a ray from the camera, through scene to the mouse if (Physics.Raycast(ray, out RaycastHit hit, 50, clickableObjects)) { // shoot ray into scene, detect where it hit TowerStateMachine tower = hit.collider.GetComponent <TowerStateMachine>(); if (tower != null && isTowerOne) { currentlySelectedTower = tower; } LightningTowerStateMachine lightningTower = hit.collider.GetComponent <LightningTowerStateMachine>(); if (tower != null && isTowerTwo) { currentlySelectedLightningTower = lightningTower; } } else { currentlySelectedTower = null; // deselect currentlySelectedLightningTower = null; } }
public virtual void OnStart(TowerStateMachine tower) { } // a start function that can be taken over by other classes public virtual void OnEnd(TowerStateMachine tower) { } // a end function that can be taken over by other classes
public abstract TowerState Update(TowerStateMachine tower); // creates a special update that can be taken over by other classes public virtual void OnStart(TowerStateMachine tower) { } // a start function that can be taken over by other classes
public abstract TowerState Update(TowerStateMachine tower); // creates a special update that can be taken over by other classes
/// <summary> /// overrides the tower update to use in this current state /// </summary> /// <param name="tower">stores a reference of the TowerStateMachine in tower</param> /// <returns>It returns back into itself until something happens</returns> public override TowerState Update(TowerStateMachine tower) { tower.GetClosestEnemy(); // locates the closest enemy to the tower return null; // return back into itself } // end update