void OrbitMovement() { if (currentState == droneState.patrolling) { if (Vector3.Distance(transform.position, player.transform.position) > maxDistanceToOrbit) { Vector3 velocity = Vector3.zero; transform.position = Vector3.Lerp( transform.position, new Vector3(player.transform.position.x, transform.position.y, player.transform.position.z), (speed / 4) * Time.deltaTime); SetRandomisations(); } else { transform.RotateAround(player.transform.position + offsetPosition, Vector3.up, angle * Time.deltaTime); } } if (currentState == droneState.attacking) { if (Vector3.Distance(transform.position, player.transform.position) > maxDistanceToCatchup) { Debug.Log("catching up to player"); StartCoroutine(CatchupToPlayer()); currentState = droneState.patrolling; transform.position = Vector3.Lerp( transform.position, new Vector3(player.transform.position.x, transform.position.y, player.transform.position.z), maxSpeed * Time.deltaTime); } } }
IEnumerator ReturnToPatrolling() { yield return(new WaitForSeconds(rateOfFire * 2f)); currentState = droneState.patrolling; yield break; }
void OnTriggerExit(Collider other) { if (other.gameObject.tag == "Alien") { Debug.Log("enemy exited collider"); currentState = droneState.patrolling; } }
void Start() { // required to create the association when we instantiate prefabs player = GameObject.Find("player"); currentState = droneState.patrolling; mySC = GetComponent <SphereCollider>(); }
private void LateUpdate() { //in the case of when the enemy is destroyed rather than exiting trigger collider if (triggered && !other) { Debug.Log("enemy destroyed or exited collider"); currentState = droneState.patrolling; } }
IEnumerator RateOfRepairTimer() { Debug.Log("repair started"); currentState = droneState.repairing; yield return(new WaitForSeconds(timeToRepair)); repairStatus.repairDroneCompleted(); Debug.Log("repair done"); SetRandomisations(); currentState = droneState.lifting; previousRepairPoint = gameObject.transform.position; yield break; }
void OnTriggerStay(Collider other) { if (other.gameObject.tag == "Alien") { Debug.Log("alien detected"); if (isCatchingUp == false) { triggered = true; this.other = other; StopCoroutine("ReturnToPatrolling"); currentState = droneState.attacking; if (canShoot == true) { GameObject trail; trail = Instantiate(weaponTrail, transform.position, Quaternion.Euler(Vector3.zero), transform); LineRenderer lr = trail.GetComponent <LineRenderer>(); if (lr != null) { lr.SetPosition(0, transform.position); lr.SetPosition(1, other.transform.position); } if (currentState != droneState.attacking) { Destroy(trail.gameObject); } else { Destroy(trail.gameObject, weaponTrailTime); } if (other.GetComponent <EnemyController>() != null) { other.GetComponent <EnemyController>().damage(damageAmount); } canShoot = false; StartCoroutine("RateOfFireTimer"); StartCoroutine("ReturnToPatrolling"); } } } }
void Start() { // required to create the association when we instantiate prefabs ship = GameObject.Find("shipChassis"); //set up array of repair points defencePositionsCount = 0; foreach (Transform child in GameObject.Find("DefencePoints").transform) { defencePositions[defencePositionsCount] = child.transform; defencePositionsCount++; } if (defencePositions.Length == 0) { Debug.LogError("No defence points in array"); } currentState = droneState.patrolling; mySC = GetComponent <SphereCollider>(); }
IEnumerator HarvestTime() { while (true) { if (harvestEffectEnabled == false && currentState == droneState.harvesting) { harvestEffectEnabled = true; harvestParticles.SetActive(true); if (currentState != droneState.harvesting) { harvestParticles.SetActive(false); } } yield return(new WaitForSeconds(harvestEffectInterval)); harvestEffectEnabled = false; currentState = droneState.returning; harvestParticles.SetActive(false); } }
void Update() { if (currentState == droneState.leaving) { desiredPosition = Vector3.MoveTowards(gameObject.transform.position, nextHarvestPoint + harvestOffset, speed * Time.deltaTime); if (Vector3.Distance(gameObject.transform.position, nextHarvestPoint + harvestOffset) < 0.1f) { currentState = droneState.harvesting; } } if (currentState == droneState.returning) { harvestParticles.SetActive(false); StopCoroutine(HarvestTime()); desiredPosition = Vector3.MoveTowards(gameObject.transform.position, ship.transform.position + harvestOffset, speed * Time.deltaTime); if (Vector3.Distance(gameObject.transform.position, ship.transform.position + harvestOffset) < 0.05f) { currentState = droneState.dropoff; } } if (currentState == droneState.dropoff) { desiredPosition = Vector3.MoveTowards(gameObject.transform.position, ship.transform.position, (speed * upDownRate) * Time.deltaTime); if (Vector3.Distance(gameObject.transform.position, ship.transform.position) < 0.1f) { SetRandomisations(); currentState = droneState.leaving; } } if (currentState == droneState.harvesting) { if (harvestEffectEnabled == false) { StartCoroutine(HarvestTime()); } } transform.position = Vector3.Lerp(transform.position, desiredPosition, Time.deltaTime * speed); }
void Start() { // required to create the association when we instantiate prefabs statusController = GameObject.Find("_StatusController"); ship = GameObject.Find("shipChassis"); //set up array of repair points repairPositionsCount = 0; foreach (Transform child in GameObject.Find("RepairPoints").transform) { repairPositions[repairPositionsCount] = child.transform; repairPositionsCount++; } if (repairPositions.Length == 0) { Debug.LogError("No repair points in array"); } currentState = droneState.lifting; previousRepairPoint = gameObject.transform.position; repairStatus = statusController.GetComponent <RepairStatus>(); SetRandomisations(); }
void Update() { Debug.Log(ship.transform.position); if (currentState == droneState.lifting) { desiredPosition = Vector3.MoveTowards(desiredPosition, previousRepairPoint + flyUpPoint, (speed * upDownRate) * Time.deltaTime); if (Vector3.Distance(gameObject.transform.position, previousRepairPoint + flyUpPoint) < 0.1f) { currentState = droneState.moving; } } if (currentState == droneState.moving) { desiredPosition = Vector3.MoveTowards(desiredPosition, nextRepairPoint + flyUpPoint, speed * Time.deltaTime); if (Vector3.Distance(gameObject.transform.position, nextRepairPoint + flyUpPoint) < 0.1f) { currentState = droneState.lowering; } } if (currentState == droneState.lowering) { desiredPosition = Vector3.MoveTowards(desiredPosition, nextRepairPoint, (speed * upDownRate) * Time.deltaTime); if (Vector3.Distance(gameObject.transform.position, nextRepairPoint) < 0.1f) { StartCoroutine("RateOfRepairTimer"); } } if (currentState == droneState.repairing) { if (repairEffectEnabled == false) { StartCoroutine(RepairEffects()); } } transform.position = Vector3.Lerp(transform.position, desiredPosition, Time.deltaTime * speed); }
void Start() { // required to create the association when we instantiate prefabs statusController = GameObject.Find("_StatusController"); ship = GameObject.Find("shipChassis"); rockList = new List <GameObject>(); harvestOffset = new Vector3(0, harvestOffsetFloat, 0); harvestParticles = GameObject.Find("harvestEffect"); foreach (GameObject rockPrefabs in GameObject.FindGameObjectsWithTag("Rock")) { rockList.Add(rockPrefabs); } currentState = droneState.dropoff; harvestParticles.SetActive(false); SetRandomisations(); }