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 alessandro_88 · Sep 27, 2013 at 06:09 PM · triggeraddingweight

Add weight every time something enters trigger

Hi! I have a project where you can play with three characters with several weights. The character ar NOT rigidbodies, thery have saved their weights in a variable in the player controller script. I want an object to be a trigger that breaks as soon as enough 'weight' is added. So every character can one by one be choosen as an active player and stand on this particular object, together they are heavy enough to break it. How can I write this for the trigger, to always add the specific weight that each character has if it enters the trigger? And in case, one character moves away before the trigger-object breaks, how to subtract it? Thanks a lot!

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

· Add your reply
  • Sort: 
avatar image
0

Answer by Krey · Sep 27, 2013 at 07:07 PM

On the 'scale' object I imagine you could do something like:

 private float WeightOnScale;
 
 void OnTriggerEnter(Collider other)
 {
     ObjectType playerScript = other.GetComponent("NAME OF OBJECT WITH CHARACTER WEIGHT");
     WeightOnScale += playerScript.WeightVariable;
 
 }
 
 void OnTriggerExit (Collider other)
 {
     ObjectType playerScript = other.GetComponent("NAME OF OBJECT WITH CHARACTER WEIGHT");
     WeightOnScale -= playerScript.WeightVariable;
 }

That code probably won't compile, and certainly won't win any best practices awards, but might be a good place to start?

I guess you would then have a check in Update() that kicks off a DoSomething() function once WeightOnScale is >= your target value.

ALTERNATIVELY: If you know that only players are going to trigger the scale (which you could do with collidable settings and putting the scale on its own specific layer), you could just increment a "How many people are on the scale" integer OnTriggerEnter and decrement it OnTriggerExit.

Comment
Add comment · 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

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

16 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

Related Questions

Tetris style math game problem... 2 Answers

Can't click gameobject when over another trigger? 1 Answer

Play Audio on Key Press when within trigger or use raycast?? 2 Answers

Showing text near object 1 Answer

How do I link/animate a light with a shuriken particle system? 2 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