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 /
avatar image
0
Question by stblue · Apr 01, 2014 at 11:03 AM · prefabfpsclone

How to control variable of prefab and its clone

I am working in FPS game i have created an enemy as soon as the game start 4 clone of enemy prefab will be instantiated, i have created a function hitCheck() for checking if enemy has been hit by bullet or not, i am incrementing a var hit, if hit increases 5 gameobject will get destroy, but the problem i am facing if i hit one clone var hit of all other clone will also get incremented, i want to know how to use hit variable so that hit will only increases if particular enemy get hit not all of its clone.

Comment
Add comment · Show 6
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 OSG · Apr 01, 2014 at 11:11 AM 0
Share

can you show your HitCheck() function?

avatar image stblue · Apr 01, 2014 at 11:16 AM 0
Share

Here is my collisiondetection script

 function OnCollisionEnter(col:Collision)
 {
     //print(col.gameObject.name);
     if(col.gameObject.name.Contains("Enemy"))
     {
         col.gameObject.GetComponent(EnemyAI).hitCheck();
     }
     Destroy(gameObject);
 }

and here is hitcheck() function

 function hitCheck()
 {
     Debug.Log(transform.name+" "+hit);
     hit++;
     var cposition:Vector3;//get current position of enemy so that we can place blood at that position
     cposition = Vector3(transform.position.x,transform.position.y,transform.position.z);
     
      Instantiate(blood,cposition,Quaternion.identity);
     if(hit>4)
     {
         Destroy(gameObject);
     }
 }
avatar image OSG · Apr 01, 2014 at 11:41 AM 0
Share

code looks fine. If I understand when player shoots 5 times in one enemy all of them becomes dead right?

avatar image Lo0NuhtiK · Apr 01, 2014 at 11:42 AM 0
Share

Sounds like you're using a static variable to me.

avatar image stblue · Apr 01, 2014 at 11:44 AM 0
Share

Exactly this is what happening, i have 3 diffrent clone of enemy if i change the hit value of one clone it reflect in hit value of all other clone, For example if i hit enemy0 with 5 bullet hit value of enemy1,enemy2 and enemy3 will also become 5 and they get destroyed.

Show more comments

0 Replies

· Add your reply
  • Sort: 

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

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

Related Questions

Array of prefabs 0 Answers

Cast Source Instantiating Error 1 Answer

instansiating prefab, then adding force in camera direction C# 0 Answers

Cloned Object does not run Scripts 2 Answers

How to change sprite on a cloned object? 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