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 /
avatar image
0
Question by colijn · Sep 11, 2019 at 01:50 PM · 1 frame

Simple score system

Im working on a really small game where you are a magnet and you float through a level gattering Ragdolls humanoids (the magnet atracts rigidbodies)

But i want it to at one point to my score for each ragdoll you gatter(you try to gatter all the ragdolls at once(you drag them behind you))

When you enter the end of the level(collider) I want it to count all the ragdolls in the collider and at the points to my score

But i dont know how to code it

Im at

 Public float Point = 1f;
 
 Ontriggerenter
 If(other.tag = ragdoll
 {
       Point
 }
 
 Not real code! Example

(This is not what my code looks like in c#)

But this only adds a couple of points if all the ragdolls are entering the collider, not all the points like i want it to

Also it wont let me chose the right topics Not a single letter works

I

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

3 Replies

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by Anaxis_Studio · Sep 12, 2019 at 12:11 AM

Practically speaking you should store the score in something like a game manager but for what you are trying to do this should work. Just attach it to your player and add a collider marked as trigger.

 public int totalPoints;
 
 // add a point if a GO tagged as "Ragdoll" enters the trigger.
 void OnTriggerEnter()
 {
     if (other.tag == "Ragdoll")
     {
         totalPoints += 1;
     }
 }

 // Remove a point if a GO tagged as "Ragdoll" leaves the trigger.
 void OnTriggerExit()
 {
     if (other.tag == "Ragdoll")
     {
         totalPoints -= 1;
     }
 }


Then it just depends how you get the score. You could do something like Player.GetComponent<ScriptName>().totalPoints from whatever script is in control of the end game stuff.

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 colijn · Sep 11, 2019 at 11:00 PM 0
Share

Alright thanks

Then one more question

Same game

I am able to switch scenes and all

So one scene is singleplayer

Second scene is local multiplayer(one pc)

I have 2 spheres Both with a code

One code Gets the rigid body of the sphere And if i press an arrow key it will add force in that direction

The other one does the same but ins$$anonymous$$d of arrow keys it uses WASD

But when i press W both spheres move up They also atract one another I have been thinking of a differend code without rigidbody then they wont atract each other but then when i press W or ASD it moves through the inviroment

Thanks

avatar image Bonfire-Boy colijn · Sep 12, 2019 at 09:50 AM 0
Share

This has nothing to do with your original question, never $$anonymous$$d being an answer to it (hence it's been converted to comment). You need to ask it as a new question.

avatar image colijn · Sep 12, 2019 at 09:15 AM 0
Share

Thank you so much this helped a lot!!

But then for my multiplayer movement.

Im still stuck there.

Code 1 gets rigidbody, And adds forch in direction of the arrow key that is pressed.

Code 2 gets rigidbody, And adds forch in direction of the WASD keythat is pressed (W = up, and so on).

But if i press arrow up the player with code 2 also moves up.

And as both are magnets atracting rigidbodies they both atract each other.

I was thinking of using a code that just changes xyz position without a rigidbody, but then they move through the environment (both player and environment have colliders).

avatar image
0

Answer by ImLife · Sep 11, 2019 at 04:08 PM

just replace point in the ifstatement with point++;

Comment
Add comment · Show 1 · 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 surfuay · Sep 11, 2019 at 05:13 PM 0
Share

yup same thing

avatar image
0

Answer by surfuay · Sep 11, 2019 at 03:49 PM

needs to be

point = point +1;

right now all you're doing is making the number 1 every time you collide, you need to tell it to increase by 1 every time you collide.

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

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

Related Questions

Can I create a script that makes an animation advance 1 frame for each keystroke? 4 Answers

Objects jitter when I move them in scene view 1 Answer

If entering collision add 1 to a byte wont work 1 Answer

how to make sprite player jump for a fixed distance 0 Answers

Rotate Object in a single frame 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