Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- /// <summary>
- /// Agent behaviour class
- /// Author: Thomas Elliot Jones
- /// </summary>
- public class FoodBehaviour : MonoBehaviour {
- public AgentBehaviour agent;
- public bool foodLeft;
- private float amount;
- private float decrement;
- private int rand;
- private Vector3 randScale;
- /*
- * If scale is 1, y = 0.1
- * If scale is 2, y = 0.5
- * If scale is 3, y = 1
- * If scale is 4, y = 1.5
- * If scale is 5, y = 2.
- */
- // Use this for initialization
- void Start () {
- foodLeft = true;
- decrement = 0.25f;
- //rand = Random.Range(1, 5);
- //Randomly assign a scale to the food blocks.
- //randScale = new Vector3(rand, rand, rand);
- //this.transform.localScale = randScale;
- // Set the amount to match its scale.
- amount = this.transform.localScale.x * this.transform.localScale.y * this.transform.localScale.z;
- }
- // Update is called once per frame
- void Update () {
- if (amount <= 0f)
- {
- foodLeft = false;
- this.gameObject.GetComponent<MeshRenderer>().enabled = false;
- this.transform.localScale = new Vector3(1f, 1f, 1f);
- //this.transform.GetComponent<SphereCollider>().radius = 3;
- }
- }
- void OnTriggerEnter(Collider other)
- {
- // Check if the object is an ant.
- if (other.gameObject.tag == "Agent")
- {
- if (this.foodLeft && (!other.gameObject.GetComponent<AgentBehaviour>().transportingFood))
- {
- amount = amount - decrement;
- // If the agent is not carrying food and has food left, decrement the amount
- // and its size accordingly.
- Vector3 newSize = new Vector3(Mathf.Pow(amount, 1f / 1.5f), Mathf.Pow(amount, 1f / 1.5f), Mathf.Pow(amount, 1f / 1.5f));
- this.transform.localScale = newSize;
- this.transform.position = new Vector3(this.transform.position.x, this.transform.localScale.y / 4.5f, this.transform.position.z);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement