Limit an amount of prefabs instantiated in javascript for Unity 5.
So I've been trying to get triggers to work properly with javascript and I can't seem to figure out how to limit the amount of prefabs created in a scene in this context when using (other.tag == "Player"). 
 function OnTriggerEnter(other : Collider)
 {
     if (other.tag == "Player")
     {
         return;
     }
         Instantiate(shot, cubePrefab.position, cubePrefab.rotation)
 
 }
 
               Again, I'd like to know how I could limit it to lets say three objects and then the player can do it again once it leaves the trigger with function OnTriggerExit(other: Collider) .
Not sure if theirs a better way to use a OnTriggerExit function without having to create another function all over again.
Thanks.
Your answer
 
             Follow this Question
Related Questions
OnTriggerExit happens when a rigibody instantiate 0 Answers
How do I destroy an instantiated game object when player leaves trigger area? 1 Answer
Why all instantiated objects get triggered when 1 is? 0 Answers
Text disappear on OnTriggerExit() 1 Answer
Instantiation of my GameObjects spell (from other script) 0 Answers