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 question was closed May 27, 2013 at 05:16 AM by Fattie for the following reason:

Duplicate Question

avatar image
0
Question by jeffreywarf · May 25, 2013 at 08:52 PM · collisiondamage

Add Object to a Variable Only When In Range

The question is a little more complicated than what I could post. I have a cube (with mesh render turned off) that has "is trigger" turned on. Here is what is supposed to happen if there is a collision:

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

1 Reply

  • Sort: 
avatar image
1
Best Answer

Answer by FL · May 25, 2013 at 10:47 PM

A - Did you really is entering in the Trigger functions? Put a debug log in the trigger function and look at http://unitygems.com/mistakes1/ , third topic.

B - enemy_health is static, so all instances and even non-instances have the same value, if you change one, you change all! Remove the "static" word.

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 jeffreywarf · May 26, 2013 at 06:07 AM 0
Share

A - That guide is REALLY helpful, thanks! Adding a Rigidbody and making it kinematic REALLY helped :) However, this now creates a NEW problem of making the enemy's attack range infinite for some reason (only when it's set to kinematic and gravity is turned off, if gravity is on and it's NOT kinematic then the attack range of the enemy works normally). But now I can attack and destroy individual enemies.

B - see, I thought it had to be static because for almost every other instance of accessing variables from other scripts I would get the compiler error "An instance of type [script with variable I am trying to access] is required to access non-static member [Name of variable]". But changing it to NOT be static worked perfectly!

avatar image Fattie · May 26, 2013 at 06:24 AM 0
Share

As a general rule never, ever, use "static". It's that simple.

It's an advanced topic, and totally irrelevant. never use static unless (in the far future!) you truly understand it. It is irrelevant here in all events.

simply read this

http://docs.unity3d.com/Documentation/ScriptReference/index.Accessing_Other_Game_Objects.html

and this

http://docs.unity3d.com/Documentation/ScriptReference/index.Accessing_Other_Components.html

and also if needed learn how to use "dontdestroyonload" (see docs, or 100s of questions here)

Follow this Question

Answers Answers and Comments

14 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

Related Questions

weapon collision with characters 1 Answer

Player take damage on collision with AI 1 Answer

Character controller mess up damage 3 Answers

Damage on collision problems... 0 Answers

Velocity data from OnCollisionEnter is delayed (incorrect) 3 Answers


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