Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 /
  • Help Room /
avatar image
0
Question by alijaj · Apr 30, 2016 at 12:15 PM · booleannot workingclonebool

bool not working on another cloned enemy

i made an enemy and i put a script c# with a bool inside and everything works fine, after i wanted to duplicate the enemy and everything is fine without errors but when i activate the bool only the original bool activates the clone doesnt activate! help please

Comment
Add comment · Show 1
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 Scribe · Apr 30, 2016 at 06:57 PM 0
Share

You can make the boolean, static if you always want the same value across all instances of a script. You could similarly look at finding or creating a Singleton class to use.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by alijaj · May 01, 2016 at 12:51 AM

@Mavina sorry for my bad english, my clone is a duplicate enemy ,and yes the original enemy has a follow bool inside that is false and when i run the game and i go in collision with a obstacle i see the bool going true and my script car calls the enemy bool to start following me and the enemy start following my player, the duplicated enemy instead remain false, i dont know how to do the same thing with the duplicated enemies(i mean they are same as the original).

Comment
Add comment · Show 3 · 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 TBruce · May 01, 2016 at 01:54 AM 0
Share

@alijaj

So far this is what I can gather, please correct me if anything is inccorect

  1. You have two GameObject's and each have an Enemy script attached (Lets call them Enemy_1 and Enemy_2).

  2. Each Enemy GameObject has a Collider attached

  3. The Enemy script has a bool variable named follow that defaults to false

  4. Now when Enemy_1 collides with an obsticle you have an OnTriggerEnter() that sets the bool variable follow is to true (you state this works fine)

Now here is where I am losing you

and my script car calls the enemy bool to start following me and the enemy start following my player, the duplicated enemy ins$$anonymous$$d remain false

The only way that the follow variable in Enemy_2 can be set to true is if it collides with an obsticle or you set up some other type of method to do this

Do you have any script that you can share?

avatar image alijaj TBruce · May 01, 2016 at 04:16 PM 0
Share

in the enemy gameobject i have the enemyscript controller where is the bool follow false inside.

i call this enemy bool to true from my other gameobject player which i control to play the game when the player collides with an obstacle.

in my playercontroll i access the enemy bool script like this public enemyscriptname boolfollow; here i assign the script or the car gameobject

void Oncoll.... { boolfollow.follow=true; //and the enemy follows me, but when i duplicate it the duplicated enemy doesnt respond to my call }

avatar image TBruce alijaj · May 01, 2016 at 05:57 PM 0
Share

@alijaj

Is your OnCollisionEnter inside of the player script? If so then OnCollisionEnter() should look something like this

 void OnCollisionEnter(Collision coll)
 {
     if ((coll.gameObject.tag == "Enemy") && (coll.gameObject.GetComponent<Enemy>() != null))
     {
         coll.gameObject.GetComponent<Enemy>().follow = true;
     }
 }

And I am not following you where you say "assign the script or the car gameobject". Also, what is boolfollow (boolfollow.follow=true)? Is boolfollow an enemy class in your player? If so boolfollow is only one enemy, you have two.

I am sorry but that tiny one line piece of script is not enough to go on. So far the best thing that I can answer you with is the OnCollisionEnter() script I posted above. I suggest that you post both your player control and your enemy script if you need any more help. This board can not provide answers to questions about script if we do not know what it looks like.

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

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

Related Questions

Trying to establish turn order in my game but bool will not toggle properly 0 Answers

Reload script not working?! 2 Answers

Why does Bool code never work in my C# Script? 1 Answer

Animator Boolean not changing to true in C#, 0 Answers

multi verification 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