示例#1
0
    // Use this for initialization
    void Start()
    {
        state          = GrowthState.Harvestable;
        growthProgress = growthTime;

        endPosition   = transform.position;
        startPosition = endPosition - (transform.forward * 1f);

        lastHarvestTime = Time.time;

        thisCollider = GetComponentInChildren <MeshCollider>();
    }
示例#2
0
    ///<summary>
    ///Harvests and hides the Crystal, but does not trigger regrowth
    ///</summary>
    public bool Harvest()
    {
        if (state == GrowthState.Harvestable)
        {
            thisCollider.enabled = false;
            state              = GrowthState.Dormant;
            growthProgress     = 0;
            transform.position = startPosition;

            lastHarvestTime = Time.time;

            return(true);
        }
        else
        {
            print("Crystal.Harvest:: Crystal not harvestable at this time!");
            return(false);
        }
    }
示例#3
0
 // Update is called once per frame
 void Update()
 {
     if (state == GrowthState.Growing)
     {
         if (growthProgress >= growthTime)
         {
             transform.position = endPosition;
             growthProgress     = growthTime;
             state = GrowthState.Harvestable;
             thisCollider.enabled = true;
         }
         else
         {
             Vector3 newPos = Vector3.Lerp(startPosition, endPosition, growthProgress / growthTime);
             transform.position = newPos;
             growthProgress    += Time.deltaTime;
         }
     }
 }
示例#4
0
    public void SetState(GrowthState newState)
    {
        state = newState;

        switch (state)
        {
        case GrowthState.Dormant:
            break;

        case GrowthState.Growing:
            break;

        case GrowthState.Harvestable:
            growthProgress     = growthTime;
            transform.position = endPosition;
            break;

        default:
            break;
        }
    }
示例#5
0
 ///<summary>
 ///Triggers the Crystal regrowth
 ///</summary>
 public void Respawn()
 {
     state              = GrowthState.Growing;
     growthProgress     = 0f;
     transform.position = startPosition;
 }