// 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>(); }
///<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); } }
// 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; } } }
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; } }
///<summary> ///Triggers the Crystal regrowth ///</summary> public void Respawn() { state = GrowthState.Growing; growthProgress = 0f; transform.position = startPosition; }