Exemplo n.º 1
0
    IEnumerator Move()
    {
        int tartgetID = Random.Range(0, targetPosition.Length);

        obj.transform.LookAt(targetPosition[tartgetID]);

        Ray        ray = new Ray(obj.transform.position, -transform.up);
        RaycastHit hit;

        while (StringView.Instance.OnHitLine(new Vector3(obj.transform.position.x, 0, obj.transform.position.z)) == false)
        {
            if (Vector3.Distance(obj.transform.position, targetPosition[tartgetID].position) < 5)
            {
                tartgetID = Random.Range(0, targetPosition.Length);
                obj.transform.LookAt(targetPosition[tartgetID]);
            }

            obj.transform.Translate(0, 0, 0.5f, Space.Self);
            ray = new Ray(obj.transform.position, -transform.up);

            //草を枯らす
            if (Physics.Raycast(ray, out hit, 10.0f, LayerMask.GetMask("Grass")))
            {
                if (hit.transform.tag == "GrownGrass")
                {
                    int _xIndex = 0;
                    int _zIndex = 0;
                    _grassManager.SearchDummyPointIndex(hit.point, out _xIndex, out _zIndex);
                    _grassManager.ChangeHasGrown(_xIndex, _zIndex, false);

                    var grassComponent = hit.collider.GetComponent <GrassesController>();
                    if (grassComponent != null)
                    {
                        grassComponent.Wither();
                    }
                    if (smoke != null)
                    {
                        smoke.Play();
                    }
                }
            }
            yield return(null);
        }

        InputController.ExtendMaxDistanceLength(extendLength);
        StartCoroutine(Del());
    }
Exemplo n.º 2
0
    void OnPassLine()
    {
        float length = 0f;

        while (length < 1f)
        {
            length += 0.01f;
            {
                Vector3 curve =
                    B_SplineCurve(
                        head.position + new Vector3(0, 3, 0),
                        tail.position + new Vector3(0, 3, 0),
                        point + new Vector3(0, 3, 0),
                        length
                        );

                ray.origin    = curve;
                ray.direction = -transform.up;

                if (Physics.Raycast(ray, out hit, 10.0f, LayerMask.GetMask("Grass")))
                {
                    int _xIndex = 0;
                    int _zIndex = 0;
                    _grassManager.SearchDummyPointIndex(hit.point, out _xIndex, out _zIndex);

                    if (hit.transform.tag == "WitheredGrass")
                    {
                        grownGrassCount++;

                        _grassManager.ChangeHasGrown(_xIndex, _zIndex, true);

                        var grassComponent = hit.collider.GetComponent <GrassesController>();
                        if (grassComponent != null)
                        {
                            int _dpIndex = _grassManager.GetDummyPoint(_xIndex, _zIndex).TexIndex;

                            if (_dpIndex != _texIndex)
                            {
                                _grassManager.ChangeTexIndex(_xIndex, _zIndex, _texIndex);
                            }

                            grassComponent.ChangeMaterials(_grassManager.GetMatPropBlock(_texIndex));
                            grassComponent.Growth();
                            grassComponent.PlayParticle();
                        }
                    }
                    else if (hit.transform.tag == "GrownGrass")
                    {
                        var grassComponent = hit.collider.GetComponent <GrassesController>();
                        if (grassComponent != null)
                        {
                            int _dpTexIndex = _grassManager.GetDummyPoint(_xIndex, _zIndex).TexIndex;

                            if (_dpTexIndex != _texIndex)
                            {
                                _grassManager.ChangeTexIndex(_xIndex, _zIndex, _texIndex);
                                grassComponent.ChangeMaterials(_grassManager.GetMatPropBlock(_texIndex));
                            }
                        }
                    }
                }
            }
        }
    }