internal static void Clean() { if (instance == null) { instance = FindObjectOfType <TankDirtiness>(); } instance.CleanTank(); }
private void Start() { if (tankDirtiness == null) { tankDirtiness = FindObjectOfType <TankDirtiness>(); } SetLength(UnityEngine.Random.Range(MinSegments, segments.Length)); }
// Start is called before the first frame update void Start() { if (tankDirtiness == null) { tankDirtiness = FindObjectOfType <TankDirtiness>(); } if (waterMaterial == null) { waterMaterial = this.GetComponent <MeshRenderer>().material; } }
// Start is called before the first frame update void Start() { if (tankDirtiness == null) { tankDirtiness = FindObjectOfType <TankDirtiness>(); } SetLength(Random.Range(1, segments.Length)); if (position != null) { this.transform.position = position.Position; this.transform.rotation = position.Rotation; } }
// Start is called before the first frame update void Start() { //Start the allowance countdown budget.allowanceCountdown = budget.allowanceTime; if (foodFeeder == null) { foodFeeder = FindObjectOfType <FoodFeeder>(); } if (tankDirtiness == null) { tankDirtiness = FindObjectOfType <TankDirtiness>(); } if (medApplicator == null) { medApplicator = FindObjectOfType <MedicineApplicator>(); } if (savedTypeManager == null) { savedTypeManager = FindObjectOfType <SavedObjectTypeManager>(); } SetMetrics(); audioSources = FindObjectsOfType <AudioSource>(); if (buttonClickAudio != null) { foreach (var button in Resources.FindObjectsOfTypeAll <Button>()) { //If the button doesn't already have a clipplayer attached, set it to the default button click sound. if (button.GetComponent <AudioClipPlayer>() == null) { button.onClick.AddListener(PlayButtonClick); } } } LoadGame(Preferences.LastTank); saveCountdown = saveInterval; //This makes sure that if we restart while paused, the timescale resets to 1.0f Time.timeScale = 1.0f; }
// Start is called before the first frame update void Start() { if (uiManager == null) { uiManager = FindObjectOfType <UIManager>(); } if (tankDirtiness == null) { tankDirtiness = FindObjectOfType <TankDirtiness>(); } if (fish == null || fish.Length == 0) { fish = FindObjectsOfType <FishController>(); } }
private void DoActions() { //If the action isn't specified and we're not performing the action, or the counter reaches zero, start a new action if (ActionCounter <= 0f || !PerformingAction) { action = null; ActionCounter = Mathf.Lerp(MinimumTimeBetweenActions, MaximumTimeBetweenActions, Random.value); float actionVal = Random.value; //If there's food available decide whether we should look for food. If the fish is over 35% hungry always look for food. if (feeder.foodAvailable.Length > 0 && ((Hunger > 0.1f && actionVal > 0.15f) || Hunger > 0.35f)) { var foodTopIdx = feeder.foodAvailable.Length - (feeder.foodAvailable.Length > 4 ? feeder.foodAvailable.Length / 4 : 1); if (foodTopIdx >= 0 && foodTopIdx < feeder.foodAvailable.Length) { foodTopIdx = feeder.foodAvailable.Length - 1; var targetFood = feeder.foodAvailable[Random.Range(0, foodTopIdx)]; actionTarget = targetFood != null ? targetFood.gameObject : null; MoveTarget = actionTarget.transform.position; action = FishAction.Eat; } else { //Move to the top of the tank in preparation for more food. MoveTarget = GetFishTarget(transform.position, true); } } else if (TankDirtiness.IsCleaning() || (Stress + actionVal > 0.75)) //If fish stress is high, decide if we should hide. If we're cleaning the tank, always hide { action = FishAction.Hide; } else if (actionVal > 0.2f && NeedsToPoop > 0.2f) //If the fish needs to poop, decide if it should poop. { action = FishAction.Poop; } else { //Otherwise we should just move around in the tank. if (actionVal < 0.05f || (Hunger > 0.35f && feeder.foodAvailable.Length == 0)) //Move to top of tank { MoveTarget = GetFishTarget(transform.position, true); } else //Move { MoveTarget = GetFishTarget(transform.position, false); } } PerformingAction = true; } else { //RaycastHit hit = new RaycastHit(); ////If the path to the target is blocked, try a new target. //if (target != null && !CheckTarget(transform.position, target.transform.position, out hit)) //{ // target.transform.position = RandomTarget(transform.position, false); //} ActionCounter -= Time.deltaTime; //If there's an actionTarget, ensure the MoveTarget is set to it. if (MoveTarget == null) { if (actionTarget != null) { MoveTarget = actionTarget.transform.position; } else { MoveTarget = GetFishTarget(transform.position, false); } } if (MoveTarget.HasValue) { //If we've reached the target. Set it to null in preparation for the next target, otherwise move towards the target. var distance = Vector3.Distance(target.transform.position, MoveTarget.Value); if (distance <= TargetReachedDistance) { if (actionTarget != null) { //If the actionTarget is food, eat it var food = actionTarget.GetComponent <Food>(); if (food != null) { Eat(food); } Destroy(actionTarget); actionTarget = null; } MoveTarget = null; PerformingAction = false; } else { //TODO: Change this to a relative motion. transform.LookAt(MoveTarget.Value); var distanceFactor = distance / tankBoundary.tankBounds.size.magnitude; rigidBody.AddRelativeForce(Vector3.forward * MoveSpeed * Time.deltaTime * distanceFactor, ForceMode.Acceleration); } } //If we're supposed to poop, do so. if (action == FishAction.Poop && fishPoopPrefab != null) { var newPoop = Instantiate(fishPoopPrefab); newPoop.GetComponent <FishPoop>().SetLengthRatio(CreatePoop()); newPoop.transform.SetPositionAndRotation(poopTarget.transform.position, poopTarget.transform.rotation); if (fishManager.fishPoopParent != null) { newPoop.transform.SetParent(fishManager.fishPoopParent.transform); } action = null; PerformingAction = false; } ////Catch all for if we don't have a MoveTarget or an actionTarget //if (!MoveTarget.HasValue && !action.HasValue) // PerformingAction = false; } }
public void CleanTank() { cleanerTimeout = cleanerCountdown; TankDirtiness.Clean(); }