Whether or not you want an enemy to vanish when the player kills them, or have a summoned weapon projectile disappear after they've spawned and done the job, destroying objects in one way or another is something that is done very frequently in games.
As provided by
(IgorAherne, 2015) from Unity Answers (an official Unity forum that may not be a 100% credible source): the character you want to die and object you want to kill the player will both need colliders attached to them, ensuring the 'is trigger' option is not enabled in the settings for the player, while it is checked for the enemy. And as sourced by
(HarshadK, 2015), another Unity answers page, the "
Destroy(gameObject);
" command is very useful as if the player wants to kill the enemy, that line of code will make them disappear. And: "
using UnityEngine;
using System.Collections;
public class Collision : MonoBehaviour {
void OnCollisionEnter2D(Collision2D coll) {
if (coll.gameObject.tag == "Lava")
Destroy(gameObject);
}
}
" Is example code from
(HarshadK, 2015), for killing and despawning a player when it collides with an object called lava. This is how a player can register a collision and cause them to die, thus making them start over. This is very important for a game to have, as without player death a video game would just become far too easy and lack any sort of challenge or competition!
No comments:
Post a Comment