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!");
}
}
}