At the moment your charakter should get damage as soon as he is in range even he isn’t hit by a bullet.
Also could you make a Debug Log right at the first line of your ApplyDamage Method to see if it is even called.
If you want to get the damage from the bullet itself, you can use different ways. One would be to attach colliders on your bullets and geht the OnCollision / OnTriggerEvent or you are looking for collision by yourself with code checking positions
Thank you for you answer martinmr, yes the character guets damage even if not hit, thats the big problem, iam looking to make the bullet make me damage instead. but i have barelly no idea how to make it, if i do somthing like this:
using UnityEngine;
using System.Collections;
public class Dañodebala : MonoBehaviour {
public float Damage = 100;
void OnCollisionEnter
( Collision info ){
info.transform.SendMessage("ApplyDammage", Damage, SendMessageOptions.DontRequireReceiver);
}
}
something like that should. Haven’t it tested so maybe there will be needed some changes.
Also if you have a huge amount of bullets it can take much performance because of rigidbody moving and collider stuff so you have to check how it will work for you
Sorry for this, i am very nob in this stuff of unity and i need this project for scholl purposes, and i have no many help thanks to you to answer this questions
i have other enemies like skeletons and mosnters that using this script in general.
After the changes made in the PlayerInfo script i dont recieve damage from him?
Whats wrong now?
code:
using UnityEngine;
using System.Collections;
public class skellyattack6 : MonoBehaviour {
public GameObject player;
public GameObject skelly6;
public float distance;
public PlayerInfo character;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
player = GameObject.FindWithTag("jugador");
skelly6 = gameObject;
distance = Vector3.Distance(player.transform.position,skelly6.transform.position);
if (distance <= 4) {
skelly6.GetComponent<Animation>().CrossFadeQueued("Run", 0.3f, QueueMode.PlayNow);
skelly6.GetComponent<Animation>().CrossFade("Attack_01");
character.ApplyDamage(1);
character.playerInCombat(true);
}
else if (distance < 50 && distance > 4.0f) {
GetComponent<FollowPath>().enabled = false;
skelly6.GetComponent<Animation>().CrossFadeQueued("Attack_01", 0.3f, QueueMode.PlayNow);
skelly6.GetComponent<Animation>().CrossFade("Run");
skelly6.transform.LookAt(player.transform.position);
transform.position = Vector3.MoveTowards(transform.position, player.transform.position, 0.18f);
character.playerInCombat(true);
}
else
{
skelly6.GetComponent<Animation>().CrossFadeQueued("Run", 0.3f, QueueMode.PlayNow);
skelly6.GetComponent<Animation>().CrossFade("Walk");
GetComponent<FollowPath>().enabled = true;
character.playerInCombat(true);
}
}
}
public void ApplyDamage(int damage) {
damageCount += damage; // Add new DamageCount
//Than check if damageCount is higher or equal to your limit 100
if (damageCount >= 100) {
//substract 30 Health from your currentHealth
currentHealth -= 30;
//check if health is lower than 0 when true it's set to 0 to avoid negative health.
if (currentHealth < 0) {
currentHealth = 0;
}
sonido2.PlayOneShot(deathClip);
healthbar.text = "Health " + currentHealth + " / 100";
damageCount = 0;
}
print(currentHealth);
}
i have 30 damage all the time, i forgot i aplyed the new code you provides and seem to works fine.
Ok , news, the mob before not taken damage before now does…it does 30 damage…
The bullets from the turret.
Makes 30 damage its well…
all makes now 30 damage…
The other problem is the skeletons when in range atack me, follow me and hit me , but when i am out of range before they stop…now its keep going followme all the time …its somthing refent to player in combat, see the general script please.
using
UnityEngine;
using System.Collections;
public class skellyattack : MonoBehaviour {
public GameObject player;
public GameObject skelly;
public float distance;
public PlayerInfo character;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
player = GameObject.FindWithTag("jugador");
skelly = gameObject;
distance = Vector3.Distance(player.transform.position,skelly.transform.position);
if (distance <= 3) {
skelly.GetComponent<Animation>().CrossFadeQueued("Run", 0.3f, QueueMode.PlayNow);
skelly.GetComponent<Animation>().CrossFade("SwingHeavy");
character.ApplyDamage(1);
character.playerInCombat(true);
}
else if (distance < 45 && distance > 3.0f) {
skelly.GetComponent<Animation>().CrossFadeQueued("SwingHeavy", 0.3f, QueueMode.PlayNow);
skelly.GetComponent<Animation>().CrossFade("Run");
skelly.transform.LookAt(player.transform.position);
transform.position = Vector3.MoveTowards(transform.position, player.transform.position, 0.18f);
character.playerInCombat(true);
}
else
//GetComponent<FollowPath>().enabled = true;
{
skelly.GetComponent<Animation>().CrossFadeQueued("Run", 0.3f, QueueMode.PlayNow);
skelly.GetComponent<Animation>().CrossFade("IdleHoldSword");
character.playerInCombat(true);
}
}
}