Beispiel #1
0
    public void Grow(PlantInstance plantInstance, LayerData layerData, TextureData textureData)
    {
        this.plantInstance = plantInstance;
        this.layerData     = layerData;

        plantData       = this.plantInstance.GetPlantData();
        plantLayerIndex = LayerData.MaskToIndex(layerData.plants);
        growDelay       = Random.Range(0f, 0.5f);

        RaycastHit hit;

        if (Physics.Raycast(transform.position, Vector3.down, out hit, Mathf.Infinity, layerData.terrain.value))
        {
            if (textureData.FoliageAllowed(hit.point))
            {
                transform.position = hit.point;
                transform.rotation = Quaternion.FromToRotation(transform.up, hit.normal) * transform.rotation;

                if (plantData.randomRotation)
                {
                    transform.RotateAround(transform.position, transform.up, Random.Range(0f, 360f));
                }

                gameObject.layer = plantLayerIndex;

                if (plantData.seedPrefab != null)
                {
                    seedVisual = Instantiate(plantData.seedPrefab, transform.position, transform.rotation);
                    seedVisual.transform.parent = transform;
                }

                float scale = plantInstance.GetScale();
                transform.localScale = new Vector3(scale, scale, scale);

                if (!plantData.instantIgnite && !plantData.isCigarette)
                {
                    SetupSaturation();
                }

                state = State.Seed;
            }
            else
            {
                Destroy(gameObject);
            }
        }
        else
        {
            Destroy(gameObject);
        }
    }
Beispiel #2
0
    public void Initialize(PlantInstance plantInstance, LayerData layerData)
    {
        this.plantInstance = plantInstance;
        this.plantData     = this.plantInstance.GetPlantData();
        this.layerData     = layerData;

        meshCollider            = GetComponent <MeshCollider>();
        meshCollider.sharedMesh = plantData.collisionMesh;

        GameObject fireObject = Instantiate(plantData.firePrefab, transform.position, transform.rotation);

        fireObject.transform.parent     = transform;
        fireObject.transform.localScale = Vector3.one;
        fire = fireObject.GetComponent <Fire>();

        fire.SetMesh(plantData.emissionMesh);

        UpdateDisplayMesh();
        initialized = true;
    }