- Home /
script on monster checks if bool on attacking player = true?
I'm creating a melee system that works but I need to redo it so I can use it online if it ever gets there. What I think I need to do is, on the monster, on triggerenter, get the player thats doing the attack and check a variable on him. Say, isAttacking = true. Then if its true do the rest. I'm wondering is this possible? Heres my example code atm that i'm trying to convert to that idea.
---Attached to enemy---
static var swordReady : boolean = false;
function Start () {
}
function Update () {
}
function OnTriggerEnter (col : Collider)
{
if(swordReady == true)
{
if(col.tag == "Weapon")
{
EnemyLogic.Enemy_Health -= 25;
print(EnemyLogic.Enemy_Health);
swordReady = false;
}
}
}
---Attached to Player---
#pragma strict
function Start () {
}
function Update ()
{
if (Input.GetButtonDown("Fire1"))
{
Enemy_Attacked.swordReady = true;
animation.Play("Attack");
animation["Attack"].wrapMode = WrapMode.Once;
}
}
Answer by Slaghton · Jan 29, 2014 at 06:20 AM
I just realized I need to reference to instances and call them locally and not globally like it is doing now.
Problem is now, is that I don't know how to call a script component from another gameobject/prefab. I made a new question and specified the problem since I have it sorted out if you'd like to look at that ^_^.
http://answers.unity3d.com/questions/630708/access-variable-from-script-on-other-gameobject.html
As long as the scripts are all on 1 prefab i don't have a problem and everything works.
Been working on this for about 10 hours so far today :.
Answer by getyour411 · Jan 29, 2014 at 02:45 AM
This appears to be nothing more than a question about how to get/set a variable on Script B from Script A, for which there are a ton of resources.
Try this http://unitygems.com/script-interaction-tutorial-getcomponent-unityscript/
Hm, maybe i'm overcomplicating things. Let me look it over again to see if I am.
Your answer
Follow this Question
Related Questions
Player rotating after wall collision 1 Answer
pushing object 2 Answers
Help with player death on collision! 2 Answers
Trouble sending message... 2 Answers