How to do it...

  1. Add the following member variable to the odor-particle script to store its parent ID:
public int parent; 
  1. 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; 
} 
  1. Initialize the odor dictionary in the proper function:
public void Start() 
{ 
    odourDic = new Dictionary<int, OdourParticle>(); 
} 
  1. 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); 
} 
  1. Remove the odor from ...

Get Unity 2018 Artificial Intelligence Cookbook - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.