- Home /
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
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.
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
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.
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).
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.
Your answer
Follow this Question
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