Error with unity shooting script: Monster Death Script Doesent Work
so i created this UNITY SHOOTING SCRIPT. it works. MOSTLY. here is the source code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class attack : MonoBehaviour {
public float monsterhealth = 30;
public float monsterhealthdecreese = 1f;
public float monsterdeath = 1f;
public Transform monster;
public Transform rangecapsule;
public float shotsmissed;
void FixedUpdate()
{
if (Input.GetKey("m"))
{
damage();
}
}
void damage()
{
if (Vector3.Distance(rangecapsule.position, monster.position) < 5)
{
if (monsterhealth < 1)
{
print("You killed a monster!");
Destroy(monster);
}
else
{
monsterhealth = (monsterhealth - 1);
print("The monster is at " + monsterhealth + " health!");
}
}
else
{
shotsmissed = (shotsmissed + 1);
print("You cannot shoot! you are to far away! (" + shotsmissed + ")");
}
}
}
the problem is that when the health is below 0 nothing happens. the code that isnt working is this.
if (monsterhealth < 1)
{
print("You killed a monster!");
Destroy(monster);
}
do you know how i can fix it? if you can then can you please tell me how with the reply button
Comment
Your answer
Follow this Question
Related Questions
Shooting Gun Script 4 Answers
errors only appear after i play the builded version of the game 0 Answers
Script creating 2 prefabs instead of 1 0 Answers
Cant Kill enemy with Raycast C# (SOLVED) 1 Answer
Shooting exactly to the center of screen 0 Answers