public static UnplantedRow GetClosestRowAtPosition(Vector3 playerPosition) { UnplantedRow closestRow = null; float smallestDistance = float.PositiveInfinity; //foreach (UnplantedRow maybeRow in _allRows) for (int i = 0; i < _allRows.Count; i++) { UnplantedRow currentRow = _allRows[i]; Vector3 difference = currentRow.transform.position - playerPosition; difference.z = 0; float currentDistance = difference.magnitude; //Mathf.Abs(_allRows[i].transform.position.y - playerPosition.y) //+ //Mathf.Abs(_allRows[i].transform.position.x - playerPosition.x); if (currentRow.currentPlant == null && currentDistance < smallestDistance) { smallestDistance = currentDistance; closestRow = _allRows[i]; } } return(closestRow); }
void Update() { if (Input.GetKey("escape")) { Application.Quit(); Debug.Log("quitIt!"); } float horizontal = Input.GetAxis("Horizontal"); HandleMovement(horizontal); if (Input.GetKeyDown(KeyCode.W)) { Debug.Log("Going up!"); StartCoroutine(nextPlane(transformLoc.transform.position)); } if (Input.GetKeyDown(KeyCode.Space)) { UnplantedRow.GetClosestRowAtPosition(this.transform.position); } Flip(horizontal); cameraX = Mathf.Lerp(cameraX, playerX, 5.0f * Time.deltaTime); }
public Plant sew_plant(UnplantedRow destinationRow) { Vector3 pos = destinationRow.transform.position; GameObject newPlant = Instantiate(plantPrefab, pos, Quaternion.identity); Plant plantScript = plantPrefab.GetComponent <Plant>(); plantScript.myRow = destinationRow; Destroy(this.gameObject);//destroy seeds gameobject return(plantScript); //** Equipments.instance.relationshipGlobalVariable.gerardRelationshipQuality = -10; }