Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
This post has been wikified, any user with enough reputation can edit it.
avatar image
0
Question by Slaghton · Jan 29, 2014 at 02:43 AM · collisionplayerboolcheckmelee

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;
     }
 }


Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

2 Replies

· Add your reply
  • Sort: 
avatar image
0
Best Answer

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.

Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image getyour411 · Feb 02, 2014 at 07:14 PM 0
Share

Glad you got it worked out.

avatar image Slaghton · Feb 02, 2014 at 09:22 PM 0
Share

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 :.

avatar image
0

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/

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Slaghton · Jan 29, 2014 at 06:00 AM 0
Share

Hm, maybe i'm overcomplicating things. Let me look it over again to see if I am.

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

18 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

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

Play annimation on collision not working. 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges