void MoveToClosestCow() { temp3V1 = transform.position; temp3V1.z = 0.0f; // first find the closest cow targetCow = Cow_controller.instances[0]; tempFloat1 = Vector2.Distance((Vector2)temp3V1, (Vector2)targetCow.transform.position); for (int i = 1; i < Cow_controller.instances.Count; i++) { tempFloat2 = Vector2.Distance((Vector2)transform.position, (Vector2)Cow_controller.instances[i].transform.position); if (tempFloat1 > tempFloat2) { tempFloat1 = tempFloat2; targetCow = Cow_controller.instances[i]; } } temp3V2 = targetCow.transform.position; temp3V2.z = 0.0f; // then move towards the closest cow transform.position = Vector3.MoveTowards(temp3V1, temp3V2, currentDifficulty.movement_speed * Time.deltaTime); }
void MouseDownCall() { // all cows will make this call comp_lineRenderer.enabled = false; // only the selected cow will show his line // check if a cow was already selected if (selected_cow == null) { // get the touch position Vector3 touchDownPosition = Input.mousePosition; touchDownPosition = Camera.main.ScreenToWorldPoint(touchDownPosition); touchDownPosition.z = transform.position.z; Bounds checkBounds = comp_renderer.bounds; checkBounds.center += Vector3.down * 0.5f; // check if this cow was selected if (checkBounds.Contains(touchDownPosition)) { // it was selected_cow = this; // create a new path comp_path.SetPath(new Vector3[] { new Vector3(transform.position.x, transform.position.y, 0.0f) }); // light it up comp_lineRenderer.enabled = true; } } }
void SmartMove() { if (targetCow == null) { targetCow = Cow_controller.instances[Random.Range(0, Cow_controller.instances.Count)]; } if (targetCow.comp_path == null) { return; } // intersection call if (!SmartMove_isIntersecting) { if (SmartMove_IntersectionCountdown <= 0 && Smart_Intersection(targetCow.comp_path.CalculatePathDistance(), targetCow.comp_path)) { SmartMove_isIntersecting = true; SmartMove_IntersectionCountdown = currentDifficulty.smartness_timeFollowingActivation; } else { SmartMove_IntersectionCountdown -= Time.deltaTime; } } temp3V1 = transform.position; temp3V1.z = 0.0f; temp3V2 = targetCow.transform.position; temp3V2.z = 0.0f; if (SmartMove_isIntersecting && Vector2.Dot((SmartMove_IntersectionPoint - temp3V1).normalized, (temp3V2 - temp3V1).normalized) > -0.95f) { temp3V2 = SmartMove_IntersectionPoint; } else { SmartMove_isIntersecting = false; temp3V2 = targetCow.transform.position; temp3V2.z = 0.0f; } transform.position = Vector3.MoveTowards(temp3V1, temp3V2, currentDifficulty.movement_speed * Time.deltaTime); // check if he reached the path point if (transform.position == SmartMove_IntersectionPoint) { SmartMove_isIntersecting = false; } else { } }
IEnumerator ChangeTarget(float delay) { yield return(new WaitForSeconds(delay)); targetCow = null; StartCoroutine(ChangeTarget(currentDifficulty.targetChangeRate)); }
IEnumerator Abduct(Cow_controller cow) { beam_gameObject.SetActive(true); GetComponent <AudioSource>().PlayOneShot(abduction_sound); if (Cow_controller.instances.Count == 1) { SceneController_gameScene.instance.GameOver(); } cow.Abduction(); temp3V1 = transform.position; temp3V1.z = temp3V1.y; temp3V2 = ship_body.position; temp3V2.z = temp3V1.y; cow.transform.position = new Vector3(cow.transform.position.x, cow.transform.position.y, temp3V1.z); abduction_progress = 0.0f; while (abduction_progress < 1.0f) { cow.transform.position = Vector3.MoveTowards(cow.transform.position, Vector3.Lerp(temp3V1, temp3V2, abduction_progress), Time.deltaTime * 3.0f); abduction_progress += Time.deltaTime / abduction_duration; yield return(null); } Destroy(cow.gameObject); GetComponent <AudioSource>().PlayOneShot(abduction_afterSound); beam_gameObject.SetActive(false); }
void MouseUpCall() { selected_cow = null; }
void StartTheGamePlay() { enabled = true; Cow_controller.StartGamePlay(); }