We will develop the scripts for representing odor particles and agents that are able to smell:
- Create the particle's script and define its member variables for computing its lifespan:
using UnityEngine; using System.Collections; public class OdourParticle : MonoBehaviour { public float timespan; private float timer; }
- Implement the Start function for proper validations:
void Start() { if (timespan < 0f) timespan = 0f; timer = timespan; }
- Implement the timer and destroy the object after its life cycle ends:
void Update() { timer -= Time.deltaTime; if (timer < 0f) Destroy(gameObject); }
- Create the class for representing the sniffer agent:
using UnityEngine; using System.Collections; using System.Collections.Generic; ...