Player attacking enemy script
HI! What I cannot seem to accomplish is to get my animated sword to deal damage to the enemy capsule. This is the script that I put on my sword:
var eHP = EnemyOne.MyHP;
var eMaxHP = EnemyOne.MyMaxHP;
var eCurrHP = EnemyOne.MyCurrHP;
var pDMG = PlayerStats.playerDMG;
var pATKspd = PlayerStats.playerATKspeed;
public var MyCurrentHP : Image;
function OnCollisionEnter (col: Collision)
{
Debug.Log("Collision Happened!");
if(col.gameObject.name == "Capsule")
{
eHP -= pDMG * pATKspd * Time.deltaTime;
Debug.Log("HP DOWN!");
MyCurrentHP.fillAmount = eHP / eMaxHP;
Debug.Log("HP Fixed");
eCurrHP = eHP;
}
}
This is the script containing all of my players attributes:
import UnityEngine.SceneManagement;
static var playerHP : float = 100f;
static var playerHPMax : float = 100f;
static var playerDMG : float = 10f;
static var playerATKspeed : float = 3f;
static var passValueCurrPlayerHP;
function Start()
{
passValueCurrPlayerHP = EnemyMovement.CurrHealth;
}
function Update()
{
passValueCurrPlayerHP = EnemyMovement.CurrHealth;
if (passValueCurrPlayerHP <= 0)
{
SceneManager.LoadScene("Death");
}
}
And this is the script that defines the enemy:
import UnityEngine.UI;
static var Me : Transform;
static var MyATK : float = 3f;
static var MyMoveSpeed : float = 5f;
static var MyATKspeed : float = 2f;
static var MyHitRange : float = 7f;
static var MyViewRange : float = 50f;
static var MyGiveUp : float = 4f;
static var MyMaxHP : int = 100;
static var MyHP : float = 100f;
var imgATK : int = 3;
static var MyCurrHP;
function Start()
{
Me = GameObject.FindWithName("Capsule").transform;
}
function Update()
{
if(MyCurrHP <= 0)
{
Destroy(Me);
}
}
I will also put screenshots in as well so you get the full picture of my current situation and hopefully help me solve it.
In the end what I want to do is, when I click my mouse button, I want the sword to swing and as it collides with the enemy, deal it some damage. But right now as it seems I can only either continuously loop the animation or not be able to do anything with it, which is also a huge problem for me. :(
I would really appriciate some help, and thank you a lot in advance!
Your answer
Follow this Question
Related Questions
Idle , Move and Attack animations 0 Answers
BCE0020 error with animation 1 Answer
BCE0043 and BCE0044 errors, expecting ), found '.' and unexpected token ) 0 Answers
Need help with automatic weapon firing! 2 Answers
Walk animation wont play but idle will 0 Answers