// Start is called before the first frame update void Start() { this._startingLocation = this._mouth.transform.position; this._currentBehaviour = PlantAttackMode.Idle; }
// Update is called once per frame void Update() { //If the player is within Range look at the player this._hungerGauge -= Time.deltaTime * this._hungerPerSecond; if (this._hungerGauge < 0) { print("dead?"); this._hungerGauge = 0; this.enabled = false; MainGame.Instance.GameOver(); } this.healthBarPercentage = Mathf.Clamp(this._hungerGauge / (this._maxHungerArea * 10f), 0.001f, 1f); for (int i = this._foodInArea.Count - 1; i >= 0; i--) { FoodInArea fia = this._foodInArea[i]; if (fia.food == null) { this._foodInArea.RemoveAt(i); continue; } fia.timeInArea += (fia.food.lifeStatus == PossibleFood.FoodStatus.Veggies) ? Time.deltaTime * (1 - this._tasteForMeat) : Time.deltaTime; if (this._currentBehaviour != PlantAttackMode.Idle) { continue; } if (fia.timeInArea > this._hungerGauge || fia.timeInArea > this._maxHungerArea) { if (fia.food == null) { continue; } //TODO: Attack charge up this._currentBehaviour = PlantAttackMode.Attacking; this._plantAnimator.Play("Bite"); this._attackPoint = fia.food.transform.position; this._attackTime = 0; } } if (this._currentBehaviour == PlantAttackMode.Attacking) { this._attackTime += Time.deltaTime; this._mouth.transform.position = Vector3.Lerp(this._startingLocation, this._attackPoint, this._attackTime / this._attackSpeed); this._mouth.LookAt(this._attackPoint); if (this._attackTime > this._attackSpeed) { this._attackTime = 0; this._currentBehaviour = PlantAttackMode.Recoiling; Collider[] hitColliders = Physics.OverlapSphere(this._mouth.position, .25f); if (hitColliders.Length > 0) { for (int n = 0; n < hitColliders.Length; n++) { if (hitColliders[n].gameObject.layer == LayerMask.NameToLayer("Plant")) { continue; } PossibleFood pf = hitColliders[n].gameObject.GetComponentInParent <PossibleFood>(); if (pf == null) { continue; } if (pf.lifeStatus == PossibleFood.FoodStatus.Veggies || pf.lifeStatus == PossibleFood.FoodStatus.Meat) { OnEat(pf); } } } } } if (this._currentBehaviour == PlantAttackMode.Recoiling) { this._attackTime += Time.deltaTime; this._mouth.transform.position = Vector3.Lerp(this._attackPoint, this._startingLocation, this._attackTime / this._attackSpeed); if (this._attackTime > this._attackSpeed) { this._attackTime = 0; this._currentBehaviour = PlantAttackMode.Idle; } } switch (this._currentBehaviour) { case PlantAttackMode.Idle: OnIdling(); break; } }