Ejemplo n.º 1
0
    /**************************************************************************************************/
    //spawn next spike recursivly
    public IEnumerator SpawnNextSpike(int num, Vector3 dir)
    {
        yield return(new WaitForSeconds(.2f));       //a little delay

        if (num != 0)
        {
            EntSpike temp = Instantiate(this.gameObject, transform.position + dir, transform.rotation).GetComponent <EntSpike>(); //spawn spike
            StartCoroutine(temp.SpawnNextSpike(num - 1, dir));                                                                    //start coroutine of next spike to spawn another in direction
        }
        StopCoroutine(SpawnNextSpike(num, dir));                                                                                  //stop this coroutine
    }
Ejemplo n.º 2
0
    /**************************************************************************************************/
    //spawns a spike on ground and the number that will spawn in a direction
    public void SpawnSpike()
    {
        Vector3      rayOrigin = transform.position + direction * -5;                           //origin for ray
        RaycastHit2D hit       = Physics2D.Raycast(rayOrigin, Vector2.down, 10, collisionMask); //raycast

        //Debug.DrawRay(rayOrigin, Vector2.down * 10, Color.yellow, 5);

        if (hit)
        {
            Vector2  spikeOrigin = hit.point + Vector2.up * 1.25f;                                                //origin for spike
            EntSpike temp        = Instantiate(spike, spikeOrigin, transform.rotation).GetComponent <EntSpike>(); //instantiate spike
            StartCoroutine(temp.SpawnNextSpike(4, direction * -3));                                               //start coroutine to spawn 4 spike 3 apart
        }
    }