Inheritance: MonoBehaviour
Example #1
0
    void OnCollisionEnter2D(Collision2D collision)
    {
        ArrowCollision arrowCollision = collision.gameObject.GetComponentInChildren <ArrowCollision>();

        if (arrowCollision)
        {
            arrowCollision._hitSource.PlayOneShot(_hitClip);
        }
        Destroy(gameObject);
    }
Example #2
0
    //检查当前哪些箭要回收,根据计时器
    private void checkAndSetFree()
    {
        GameObject arrow = null;

        foreach (GameObject a in arrows)
        {
            ArrowCollision ac = a.GetComponent <ArrowCollision>();
            if (ac.timer <= 0)  //超时
            {
                arrow = a;
                break;
            }
        }
        if (arrow != null)
        {
            //找到超时的箭就回收
            arrowFactory.setFree(arrow);
            arrows.Remove(arrow);
            Debug.Log("Set Free in controller");
        }
    }