Skip to content

Commit

Permalink
Changing physics layers with player immunity to prevent enemy collisi…
Browse files Browse the repository at this point in the history
…ons while immune
  • Loading branch information
jonuy committed Jul 31, 2014
1 parent 5ced135 commit a61b2c4
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
Binary file modified Assets/Scenes/Level1.unity
Binary file not shown.
14 changes: 12 additions & 2 deletions Assets/Scripts/PlayerController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ void Awake() {
walkJumpForce = runJumpForce;
}

isImmune = true;
SetIsImmune(true);
}

void Update() {
Expand Down Expand Up @@ -296,7 +296,9 @@ private void _respawn() {
ignoreInput = false;

// Reset layer to allow enemy collisions
gameObject.layer = 13; // "Player"
if (!isImmune) {
gameObject.layer = 13; // "Player"
}

// Reset camera position
GameObject camera = GameObject.FindGameObjectWithTag("MainCamera");
Expand All @@ -306,6 +308,14 @@ private void _respawn() {

public void SetIsImmune(bool isImmune) {
this.isImmune = isImmune;

// Set physics layer to control if enemies collide with player or not.
if (this.isImmune) {
gameObject.layer = 10; // "EnemyIgnore"
}
else {
gameObject.layer = 13; // "Player"
}
}

}

0 comments on commit a61b2c4

Please sign in to comment.