I don't if I am stupid,but it confuses me really.

public class RayShooter : MonoBehaviour {
private Ray ray;
private Vector3 rayStartPoint;
private Camera _camera;
RaycastHit rayHit;
private GameObject ball;

// Use this for initialization


void Start () {
_camera =GetComponent<Camera>();
}

// Update is called once per frame
void Update () 

{
    if (Input.GetMouseButtonDown(0))
    {
    rayStartPoint=new Vector3(_camera.pixelWidth/2,_camera .pixelHeight/2,0);
    
    ray=_camera.ScreenPointToRay(rayStartPoint);
    Physics.Raycast(ray, out rayHit);
   
 ball = GameObject.CreatePrimitive(PrimitiveType.Sphere);
   ball.transform.position = rayHit.point;
    
        StartCoroutine("Creatball");
        
    }
   
**}

The Script below I write down is to make a Sphere on the RayCastHit point and destroy it 0.3 seconds later.but when I click the mouse quickly enough,some spheres are not destroied,why ? When I move the script “ball = GameObject.CreatePrimitive(PrimitiveType.Sphere); ball.transform.position = rayHit.point;” into the coroutine method(add a script in front :”GameObject ball;“ )and delete the script “private GameObjet ball”.it is ok.everyball is destroid,why**

private IEnumerator Creatball()
{

    yield return new WaitForSeconds(0.3f);
    Destroy( ball); 
}

}***

If I write like this ,every ball is destroied ,and it is ok.

using UnityEngine;
using System.Collections;

public class RayShooter : MonoBehaviour {
private Ray ray;
private Vector3 rayStartPoint;
private Camera _camera;
RaycastHit rayHit;
// GameObject ball;

// Use this for initialization


void Start () {
_camera =GetComponent<Camera>();
}

// Update is called once per frame
void Update () 

{

    if (Input.GetMouseButtonDown(0))
    {
    rayStartPoint=new Vector3(_camera.pixelWidth/2,_camera .pixelHeight/2,0);
    
    ray=_camera.ScreenPointToRay(rayStartPoint);

    Physics.Raycast(ray, out rayHit);
   

    //To Show the ball on the Object hit;
   
        
      // ball = GameObject.CreatePrimitive(PrimitiveType.Sphere);
       //ball.transform.position = rayHit.point;

        StartCoroutine("Creatball");
        
    }

   
}

private IEnumerator  Creatball()
{

   
   GameObject ball = GameObject.CreatePrimitive(PrimitiveType.Sphere);
   ball.transform.position = rayHit.point;

    yield return new WaitForSeconds(0.3f);
    Destroy( ball); 

}

}