示例#1
0
    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);
    }
示例#2
0
文件: Player.cs 项目: eabosch/Idyll
    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);
    }
示例#3
0
文件: Seeds.cs 项目: eabosch/Idyll
    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;
    }