• 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 question was closed Feb 04, 2015 at 06:43 PM by fafase for the following reason:

Duplicate Question

avatar image
Question by imaethan · Feb 04, 2015 at 06:41 PM · javascriptenemy

When one enemy is affected, they all are...

Basically I understand why t$$anonymous$$s is happening, with me using public static variables. When you shoot or kick an enemy in a specific place it's switched out with another version w$$anonymous$$ch is damaged... I'm wondering how I go about making t$$anonymous$$s an instance for each enemy. Instead of blowing one enemies head off to see them all pop off on other enemies. The public static variables are being called from the weapon scripts. Like when you kick the enemy in the head, guardTest.head = true.

 var bfHeadHelm : GameObject;
 var bfHeadNoHelm : GameObject;
 var bfChest : GameObject;
 var bfArmL : GameObject;
 var bfArmR : GameObject;
 var bflegs : GameObject;
 //var bfHelmet : GameObject;
 
 
 var afArmL : GameObject;
 var afArmR : GameObject;
 var afHeadNoHelm : GameObject;
 var afHelmet : GameObject;
 var afHeadHelm : GameObject;
 
 var neckBlood : GameObject;
 var neckBlood2 : GameObject;
 var armRBlood : GameObject;
 var armLBlood : GameObject;
 var headKickBlood : GameObject;
 
 var bodyRagdoll : GameObject;
 var bodyRagdollArms : GameObject;
 var bodyRagdollLeftArm : GameObject;
 var bodyRagdollRightArm : GameObject;
 var body : GameObject;
 var bodyRagdollFull : GameObject;
 var bodyRagdollHeadKick : GameObject;
 
 
 public static var head : boolean = false;
 public static var headExplode : boolean = false;
 public static var chest : boolean = false;
 public static var armL : boolean = false;
 public static var armR : boolean = false;
 public static var helmet : boolean = true;
 
 public static var helmetDamage : float = 0f;
 public static var headDamage : float = 0f;
 public static var rJointDamage : float = 0f;
 public static var lJointDamage : float = 0f;
 
 public static var kicked : boolean = false;
 public static var headKicked : boolean = false;
 
 function Start () {
 
 }
 
 function Update () {
 
 if (helmet == false){
 
 bfHeadHelm.active = false;
 bfHeadNoHelm.active = true;
 afHelmet.active = true;
 
 }
 
 if (head == true && helmet == false && armL == false && armR == false){
 
 bfArmL.active = false;
 bfArmR.active = false;
 bfHeadNoHelm.active = false;
 afHeadNoHelm.active = true;
 neckBlood.active = true;
 
 body.active = false;
 bodyRagdollArms.active = true;
 
 }
 
 if (head == true && helmet == false && armL == true && armR == true){
 
 bfHeadNoHelm.active = false;
 afHeadNoHelm.active = true;
 neckBlood.active = true;
 
 body.active = false;
 bodyRagdoll.active = true;
 
 }
 
 
 if (head == true && helmet == false && armL == false && armR == true){
 
 bfHeadNoHelm.active = false;
 afHeadNoHelm.active = true;
 neckBlood.active = true;
 bfArmL.active = false;
 body.active = false;
 bodyRagdollRightArm.active = true;
 
 }
 
 if (head == true && helmet == false && armL == true && armR == false){
 
 bfHeadNoHelm.active = false;
 afHeadNoHelm.active = true;
 neckBlood.active = true;
 bfArmR.active = false;
 body.active = false;
 bodyRagdollLeftArm.active = true;
 
 }
 
 if (headExplode == true){
 
 afHeadNoHelm.active = false;
 
 }
 
 if (armR == true){
 
 bfArmR.active = false;
 afArmR.active = true;
 armRBlood.active = true;
 
 }
 
 if (armL == true){
 
 bfArmL.active = false;
 afArmL.active = true;
 armLBlood.active = true;
 
 }
 
 if (kicked == true){
 body.active = false;
 bodyRagdollFull.active = true;
 bfHeadHelm.active = false;
 bfArmL.active = false;
 bfArmR.active = false;
 
 
 }
 
 if (headKicked == true){
 body.active = false;
 neckBlood2.active = true;
 bodyRagdollHeadKick.active = true;
 afHeadHelm.active = true;
 bfHeadHelm.active = false;
 bfArmL.active = false;
 bfArmR.active = false;
 
 
 }
 
 }
Comment

People who like this

0 Show 4
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 fafase · Feb 04, 2015 at 06:44 PM 1
Share

You need to look for static vs GetComponent for script interaction

avatar image imaethan · Feb 04, 2015 at 07:03 PM 0
Share

Could you explain a bit more about using GetComponent to do this? I've googled and not found much useful information.

avatar image tanoshimi · Feb 04, 2015 at 07:07 PM 1
Share

You didn't find http://unity3d.com/learn/tutorials/modules/beginner/scripting/getcomponent ?

avatar image imaethan · Feb 04, 2015 at 07:08 PM 0
Share

I didn't somehow. Thank you.

0 Replies

  • Sort: 

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

19 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 avatar image

Related Questions

Enemy moving sideways 1 Answer

Checking Enemies In An Area. 1 Answer

why won't my code work? 1 Answer

Can someone help me fix my Javascript for Flickering Light? 6 Answers

Enemy Shoots At Player When A Certain Distance 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