In this recipe, we take a mixed approach to tag vertices with a given odor particle that collides with it.
The vertices should have a broad collider attached so that they catch the odor particles nearby.
public int parent;
using UnityEngine; using System.Collections; using System.Collections.Generic; public class VertexOdour : Vertex { private Dictionary<int, OdourParticle> odourDic; }
public void Start() { odourDic = new Dictionary<int, OdourParticle>(); }
public void OnCollisionEnter(Collision coll) { OdourOdourParticle op; op = coll.gameObject.GetComponent<OdourParticle>(); if (op == null) return; int id = op.parent; odourDic.Add(id, op); }
public void OnCollisionExit(Collision coll) { OdourParticle op; op = coll.gameObject.GetComponent<OdourParticle>(); if (op == null) return; int id = op.parent; odourDic.Remove(id); }
public bool HasOdour() { if (odourDic.Values.Count == 0) return false; return true; }
public bool OdourExists(int id) { return odourDic.ContainsKey(id); }
The odor particles collide with the vertices, being indexed in their odor dictionary. From that point on, our agents can check whether a given odor is registered in a vertex nearby.