- Home /
Pressing "Fire2" Spawns and removes object on click
I am creating a game with a person with a flashlight, and the only way to avoid the monsters, is to turn your flashlight off. Basically what I am trying to create is an object that spawns when the flashlight is on, making the monster move towards you, and de-spawns when the flashlight is off. I am really bad at spawning, so could someone help me? Here is my flashlight script
var light1:Light; var light2:Light; var lightTimer : float = 0.0; var lightBattery : float = 8.0;
public var lightOn : boolean = false;
function Update () {
if (Input.GetButtonDown ("Fire2"))
{ audio.Play(); lightOn = !lightOn;
light1.enabled = lightOn; light2.enabled = lightOn;
} }
You can use instantiate to create an instance of your monster in the location that you desire using an if statement checking if the lightOn is true. If you have a tag on the monster then you can check for a tag and destroy using something like Destroy(GameObject.FindWithTag("$$anonymous$$onster")); when lightOn is false.
Your answer
Follow this Question
Related Questions
script dosnt creat object where i want it to 1 Answer
Spawn object problem 1 Answer
Error... that I don't understand. 3 Answers
error with footsteps script 1 Answer
Is it good to have many scripts? 1 Answer