I want a score +10 if I kill an opponent but I don’t know how a score system is scripted … please for quick help!
have one a script for me that will do that what i will?
Thx JuliGamer
I want a score +10 if I kill an opponent but I don’t know how a score system is scripted … please for quick help!
have one a script for me that will do that what i will?
Thx JuliGamer
There plenty of videos on YouTube that can show you how. I wont do it for you, but basically you will need a variable with the type Int named Score or something. Then, you need a trigger to increment the score by +10 every time it is triggered. Since you want the trigger to be for when a player kills an opponent, you need to increment the score when the enemy dies.
Do you have a death script on the enemy so the sprite and gameobject disappears? If so, it would be a great place to increment the score there.
“I want a score +10 if I kill an opponent but I don’t know how a score system is scripted … please for quick help!”
That sounds like code begging and BTW this question doesn’t have anything to with 2D features either…
I do not know
@Cornysam
Sounds like a good time to learn.
https://www.youtube.com/results?search_query=score+system+unity+2d
Pick one of those videos and you’ll figure it out. Post your code here if you are still having issues. Remember to use code tags so its easy to read.
I have one yet to my player assign but it will not turn the Score up… here is the code (Sorry for my Bad English)
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class Score1 : MonoBehaviour
{
private int currentScore;
public Text scoreText;
// Use this for initialization
void Start()
{
currentScore = 0;
}
// Update is called once per frame
void FixedUpdate()
{
scoreText.text = "" + currentScore;
}
void OnCollisionEnter2D(Collision2D col)
{
if (col.gameObject.tag == "Monster")
{
currentScore += 10;
}
}
}
here is my project:
https://drive.google.com/drive/folders/1C0dcDBsHMifHrZ92XAPazf5i12UAMhk6?usp=sharing
Okay, this is much better. First off, change that FixedUpdate to just regular Update. Use FixedUpdate only for Physics related input or functions.
Second, make sure you have a Rigidbody2D and a Collider2D (it can be Box, Circle, etc. as long as it is 2D) on the object you are trying to collide with. Also, make sure your Rigidbody2D is not set to Kinematic.
Third, throw a Debug.Log function in your OnCollisionEnter2D where currentScore += 10; is. This will let you know if the function is being called. Note: Since you are a beginner, use Debug.Logs as much as possible as it will help you immensely going forward. This will help with debugging.
Fourth, your english is fine! Keep it up!
If it still does not work, check to make sure your variables are assigned in the inspector, scripts are attached to the appropriate objects and then send a snippet of your inspector (either from the player or the monster)
Nothing is in the log… thats weird
So that means that the function wasnt called. Which means that there is something wrong with that function. Put one in the Start function too to make sure the script it working.
In update is a debug but not at OnCollisionEnter2d…
I have 1 hour left … and i must present it tomorrow…
Change OnCollisionEnter2D to OnTriggerEnter2D. Change the Collider2D in the inspector to be a Trigger (check the box). I have better luck with OnTriggerEnter2D anyways.
For collisions and Triggers to work (no matter if 2D or 3D) one object must have Collider2D and RigidBody2D. Another needs Collider2D. See that you have those, otherwise collisions don’t register.
Edit: actually this was already said, but this is what usually happens…
Unfortionatlly it totally not worked at all
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class Score1 : MonoBehaviour
{
private int currentScore;
public Text scoreText;
// Use this for initialization
void Start()
{
currentScore = 0;
Debug.Log("WorkedStart");
}
// Update is called once per frame
void Update()
{
scoreText.text = "" + currentScore;
Debug.Log("Worked");
}
void OnTriggerEnter2D(Collision2D col)
{
if (col.gameObject.tag == "Monster")
{
currentScore += 10;
}
}
}
Make sure your script with OnTriggerEnter2D is attached to a GameObject that has the collider (it could be either player or object player collides with).
But in this case, as you check the tag, you must add the script to player’s GameObject. So also check that your monster objects in scene actually have that tag.
it both has colliders
Check those things I mentioned above (I added a few things in my post above).
The Monsters have both the Monster-Tag!
In your OnTriggerEnter2D parameters, change Collision2D to Collider2D