UNITY shooting script does nothing
UNITY shooting script wont work. i asigned alll values. how can i fix it?
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;
// Use this for initialization
void Start ()
{
}
// Update is called once per frame
void FixedUpdate ()
{
if (Input.GetKey("r"))
{
damage();
}
}
void damage()
{
if (Vector3.Distance(rangecapsule.position, monster.position) < 1)
{
monsterhealth = monsterhealth - monsterhealthdecreese;
print("The monster is at " + monsterhealth + " health!");
if (monsterhealth < monsterdeath)
{
print("You killed a monster!");
Destroy(monster);
}
}
else
{
print("You cannot shoot! you are to far away!");
}
}
}
Comment
Best Answer
Answer by connorwforman · Jan 18, 2018 at 04:24 PM
Change monsterhealth = monsterhealth - monsterhealthdecreese;
to monsterhealth = monsterhealth -= monsterhealthdecreese;
That will make sure that monsterhealth is equal to monsterhealth, with the amount of decrease removed from it.
Your answer
Follow this Question
Related Questions
Change music when spotted by Enemy Unity 5.0 0 Answers
sound buzzing enemy dies 1 Answer
How do I make a script for camera recoil recovery? 0 Answers
Problem with boat script 0 Answers
Why do I keep getting this error? 1 Answer