//derez //tracks enemy for duration it spends inside of an attraction //increments money and capacity of attraction public IEnumerator derez(float timeSpentIn, BAttraction Attractor) { gameObject.GetComponent <Renderer>().enabled = false; Attractor.currCapacity++; ClickToBuild UIcontrol = GameObject.Find("PlayerController").GetComponent <ClickToBuild>(); UIcontrol.currMoney += Attractor.moneyEarned; yield return(new WaitForSeconds(timeSpentIn)); Attractor.currCapacity--; gameObject.GetComponent <Renderer>().enabled = true; isLeaving = true; isCaptured = false; yield return(moveTowardsExit(capturedTransform)); }
//OnTriggerEnter2D //Handles collisions with all objects void OnTriggerEnter2D(Collider2D other) { //When an enemy walks into field of an attraction if (other.transform.tag == "Attraction Collider") { GameObject Attractor = other.transform.parent.gameObject; waveEntered = GameObject.Find("SpawnPoint").GetComponent <SpawnControlScript>().waveNumber; if (Attractor.GetComponent <BAttraction>().currCapacity < Attractor.GetComponent <BAttraction>().maxCapacity) { transform.GetComponent <Rigidbody2D>().velocity = new Vector3(0, 0, 0); isCaptured = true; capturedTransform = transform.position; StartCoroutine(moveTowardsAttractor(Attractor.transform)); } } //When an enemy walks into attraction else if (other.transform.tag == "Attraction") { BAttraction Attractor = other.transform.gameObject.GetComponent <BAttraction>(); StartCoroutine(derez(Attractor.timeSpentIn, Attractor)); } //waypoint system for determining path enemies should follow else if (other.transform.tag == "Waypoint") { if (!isLeaving) { ++nextWayPoint; moveTowardsNext(); } } //move off screen else if (other.transform.tag == "Final") { ++nextWayPoint; moveTowardsNext(); } //adjust variables if enemy makes it into town else if (other.transform.tag == "Town") { //Debug.Log("good1"); if (isLast) { GameObject.Find("StartButton").GetComponent <Button>().interactable = true; isLast = false; } TownControlScript control = other.transform.gameObject.GetComponent <TownControlScript>(); control.trashCount += hotelSpace; if (control.trashCount > control.trashCapacity) { SceneManager.LoadScene("gameOverScene"); } isActive = false; Destroy(this.gameObject); } else if (other.transform.tag == "Hotel") { isActive = false; Destroy(this.gameObject); } }