Skip to content

Instantly share code, notes, and snippets.

@JaiParakh
Created January 13, 2026 15:51
Show Gist options
  • Select an option

  • Save JaiParakh/09006c03894f1ccd4ce2cf5698564e10 to your computer and use it in GitHub Desktop.

Select an option

Save JaiParakh/09006c03894f1ccd4ce2cf5698564e10 to your computer and use it in GitHub Desktop.
using UnityEngine;
public class SmellSource : MonoBehaviour
{
// Here you can add your smell types
public enum SmellType { Treasure }
// Set a default type
public SmellType smellType = SmellType.Treasure;
// In what radius can the smell be detected
public float smellRange = 50f;
// This calculates how strong the smell is at any position
public float getSmellIntensityAt(Vector3 detector_position)
{
float distance = Vector3.Distance(transform.position, detector_position);
// If too far away, no smell
if (distance > smellRange)
return 0f;
// Smell gets weaker with distance
// Close: 1.0, Far: 0.1
float intensity = 1f / (1f + distance * 0.1f);
return intensity;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment