- Add the following member variable to the odor-particle script to store its parent ID:
public int parent;
- Create the new odor-enabled class, deriving from the original vertex:
using UnityEngine; using System.Collections; using System.Collections.Generic; public class VertexOdour : Vertex { private Dictionary<int, OdourParticle> odourDic; }
- Initialize the odor dictionary in the proper function:
public void Start() { odourDic = new Dictionary<int, OdourParticle>(); }
- Add the odor to the vertex's dictionary:
public void OnCollisionEnter(Collision coll) { OdourOdourParticle op; op = coll.gameObject.GetComponent<OdourParticle>(); if (op == null) return; int id = op.parent; odourDic.Add(id, op); }
- Remove the odor from the vertex's dictionary:
public void OnCollisionExit(Collision coll) { OdourParticle op; op = coll.gameObject.GetComponent<OdourParticle>(); if (op == null) return; int id = op.parent; odourDic.Remove(id); }
- Implement the function for checking whether any odor is tagged:
public bool HasOdour() { if (odourDic.Values.Count == 0) return false; return true; }
- Implement the function for checking whether a given type of odor is indexed in the vertex:
public bool OdourExists(int id) { return odourDic.ContainsKey(id); }