Search Unity

I'm a newbie, begin with Tower Bridge Defence

Discussion in '2D' started by sweetxdream, May 29, 2014.

  1. sweetxdream

    sweetxdream

    Joined:
    May 29, 2014
    Posts:
    1
    Hi everyboby, I'm a newbie and I begin research Unity with Tower Birdge Defence project. Anyone same with me? We are together research this.
    I have some problems, in prefab enemy1 (Assets->Prefabs->enemy1) have script Enemy and have:
    void FixedUpdate ()
    {
    // Create an array of all the colliders in front of the enemy.
    Collider2D[] frontHits = Physics2D.OverlapPointAll(frontCheck.position, 1);

    // Check each of the colliders.
    foreach(Collider2D c in frontHits)
    {
    // If any of the colliders is an Obstacle...
    if(c.tag == "Obstacle")
    {
    // ... Flip the enemy and stop checking the other colliders.
    Flip ();
    break;
    }
    }

    // Set the enemy's velocity to moveSpeed in the x direction.
    rigidbody2D.velocity = new Vector2(transform.localScale.x * moveSpeed, rigidbody2D.velocity.y);

    // If the enemy has one hit point left and has a damagedEnemy sprite...
    if(HP == 1 damagedEnemy != null)
    // ... set the sprite renderer's sprite to be the damagedEnemy sprite.
    ren.sprite = damagedEnemy;

    // If the enemy has zero or fewer hit points and isn't dead yet...
    if(HP <= 0 !dead)
    // ... call the death function.
    Death ();
    }


    // Create an array of all the colliders in front of the enemy.
    Collider2D[] frontHits = Physics2D.OverlapPointAll(frontCheck.position, 1);
    Why is param second of OverlapPointAll fucntion is 1?
    In docs, param second described is layerMask, I don't understand what is layerMask in this project, and why it equals 1?
     
    Last edited: May 29, 2014