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 instead 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
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.