Please! Can anybody help me with a scorescript? I have no idea on how to do it!
Example: shooting an enemy gives you 100 points or something!
Help!
The score can be as simple as a variable in the playerās script than just gets incremented when an enemy gets hit. Are you having a problem detecting when the enemy is hit or displaying the score or⦠what? Any more detail you can give would be very useful.
I havent i even written any script yet becouse i dont know how to script it! An example code would be very useful.
Start something and I will add to it.
you can try something like that(very basic way)ā¦
Put this script on any object(just make a cube or whatever):
var hitPoints : int = 1000;
var scoreManager : ScoreManager;
function ApplyDamage (damage : int) {
hitPoints -= damage;
scoreManager.AddScore(damage);
}
And this will be your āscore managerā:
var scoreText : GUIText;
var score : int;
function Start() {
scoreText.text = "" + 0;
}
function AddScore (value:int) {
score += value;
scoreText.text = "" + score;
}
couldnāt get that to work iāll try to figure this one out by myself since i doesnt feel like im getting any help! No offense!
can u post it for me plz
⦠Really? No help? OneManArmy3Dās scripts worked perfectly!
Since OneManArmy3Dās didnt code help you heres a step by step guide to get it to workā¦
1.) Make an Empty Game Object in your scene and name it PointsGO.
2.) Create 2 new javascripts in your project, Name one ScoreManager and the other PlayerScore
3.) Drag the ScoreManager onto the Empty GO and the PlayerScore Onto the player.
4.) Put this code into the ScoreManager Script:
var Points : int;
function AddPoints(PointsToAdd : int){
Points += PointsToAdd;
}
5.) Put this code into the PlayerScore Script:
//Call this function when you kill an enemy, so when the enemys hp = 0 call this function and the delete the enemy
function OnKillOfEnemy(){
var Scr = GameObject.Find("PointsGO").getComponent("ScoreManager");
Scr.AddPoints(100);
}
6.) This will work, there is no āit might workā¦maybeā, It will! So dont say ohh i cant get it working
-Regards
Anthony Faraci
Not for me!
Sorry but i must have expressed myself bad i also it to display the score!
Hutzizm dude sorry to say but your attitude is really bad!
To display score simple via C# u can do this.
void OnGUI()
{
GUI.Label(new Rect(10, 10, 60, 20), "Score: " + Score);
}
Where Score is your var.
Looks at this video. Unity 3D Student - 3d Modelling
what about this score ststym?
public var picupObj: GameObject;
private var score: int;
function OnGUI()
{
// ŃŠøŃŃŠµŠ¼ в веŃŃ
Ń ŃŠŗŃана Š½Š°Ń ŃŃŠµŃ
GUI.Label(Rect(0,0,512,50),"SCORE: " +score);
}
function Start() {
score=99999;
}
function Update () {
ScoreDown();
}
function ScoreDown(){
score--;
}
but how I can next:
When player is moving score is downing, but when Player is not moving and just staying? speed of score downing il getting a little slower?
can anyone help me about this⦠i cant increase my score⦠please⦠heres the codes⦠PLEASE
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using UnityEngine.UI;
public class Board : MonoBehaviour
{
public Text countText;
public Text gameOverText;
public List gems = new List();
public int GridWidth;
public int GridHeight;
public GameObject gemPrefab;
public Gem lastGem;
public Vector3 gem1Start,gem1End,gem2Start,gem2End;
public bool isSwapping = false;
public Gem gem1,gem2;
public float startTime;
public float SwapRate =1;
public int AmountToMatch =3;
public bool isMatched = false;
public Text scoreText;
private GameObject Gem;
private int count;
// Use this for initialization
void Start ()
{
if(!PlayerPrefs.HasKey(āHiScoreā))
{
PlayerPrefs.SetInt(āHiScoreā, 0);
}
scoreText.text = "Score: 0 - High Score: " + PlayerPrefs.GetInt (āHiScoreā);
count = -10;
SetCountText ();
gameOverText.text= āā;
for(int y=0;y<GridHeight;y++)
{
for(int x=0;x<GridWidth;x++)
{
GameObject g = Instantiate(gemPrefab,new Vector3(x,y,0),Quaternion.identity)as GameObject;
g.transform.parent = gameObject.transform;
gems.Add(g.GetComponent());
}
}
gameObject.transform.position = new Vector3(-2.5f,-2f,0);
}
// Update is called once per frame
void Update ()
{
if (isMatched)
{
for (int i=0;i<gems.Count;i++)
{
if (gems*.isMatched)*
{
gems*.CreateGem();*
gems*.transform.position = new Vector3(*
gems .transform.position.x,
gems .transform.position.y + 6,
gems .transform.position.z);
}
}
isMatched = false;
}
else if(isSwapping)
{
MoveGem(gem1,gem1End,gem1Start);
MoveNegGem(gem2,gem2End,gem2Start);
if (Vector3.Distance(gem1.transform.position, gem1End) < .1f|| Vector3.Distance (gem2.transform.position,gem2End)<.1f)
{
gem1.transform.position = gem1End;
gem2.transform.position = gem2End;
gem1.ToggleSelector();
gem2.ToggleSelector();
lastGem = null;
isSwapping = false;
TogglePhysics (false);
CheckMatch ();
}
}
else if(!DetermineBoardState())
{
for(int i =0;i<gems.Count;i++)
{
CheckForNearbyMatches(gems*);*
}
}
}
public bool DetermineBoardState()
{
for (int i =0;i<gems.Count;i++)
{
if(gems*.transform.localPosition.y>4)*
{
return true;
}
else if(gems*.GetComponent().velocity.y>.1f)*
{
return true;
}
}
return false;
}
public void CheckMatch()
{
List gem1List = new List();
List gem2List = new List();
ConstructMatchList(gem1.color,gem1,gem1.XCoord,gem1.YCoord,ref gem1List);
FixMatchList(gem1,gem1List);
ConstructMatchList(gem2.color,gem2,gem2.XCoord,gem2.YCoord,ref gem2List);
FixMatchList(gem2,gem2List);
count = count + 1;
SetCountText ();
}
void SetCountText()
{
countText.text = "Count: " + count.ToString ();
if(count >= 0)
{
gameOverText.text = āGAME OVER!ā;
Application.LoadLevel(4);
}
}
public void CheckForNearbyMatches(Gem g)
{
List gemList = new List();
ConstructMatchList (g.color,g,g.XCoord,g.YCoord, ref gemList);
FixMatchList (g,gemList);
}
public void ConstructMatchList(string color,Gem gem,int XCoord,int YCoord,ref ListMatchList)
{
if(gem == null)
{
return;
}
else if(gem.color != color)
{
return;
}
else if(MatchList.Contains(gem))
{
return;
}
else
{
MatchList.Add(gem);
if(XCoord == gem.XCoord || YCoord == gem.YCoord)
{
foreach(Gem g in gem.Neighbors)
{
ConstructMatchList(color,g,XCoord,YCoord,ref MatchList);
}
}
}
}
public void FixMatchList(Gem gem, ListListToFix)
{
List rows = new List ();
List collumns = new List ();
for (int i=0; i<ListToFix.Count; i++)
{
if(gem.XCoord == ListToFix*.XCoord)*
{
rows.Add(ListToFix*);*
}
if(gem.YCoord == ListToFix*.YCoord)*
{
collumns.Add(ListToFix*);*
}
}
if (rows.Count >= AmountToMatch)
{
isMatched = true;
for(int i=0;i<rows.Count;i++)
{
rows*.isMatched = true;*
}
}
if (collumns.Count >= AmountToMatch)
{
if (collumns.Count > PlayerPrefs.GetInt (āHiScoreā))
{
PlayerPrefs.SetInt (āHiScoreā, collumns.Count);
}
scoreText.text = "Score: " + collumns.Count + " - High Score: " + PlayerPrefs.GetInt (āHiScoreā);
isMatched = true;
for(int i=0;i<collumns.Count;i++)
{
collumns*.isMatched = true;*
}
}
}
public void MoveGem(Gem gemToMove,Vector3 toPos,Vector3 fromPos)
{
Vector3 center = (fromPos + toPos) * .5f;
center -= new Vector3 (0, 0,.1f);
Vector3 riseRelCenter = fromPos - center;
Vector3 setRelCenter = toPos - center;
float fracComplete = (Time.time - startTime) / SwapRate;
gemToMove.transform.position = Vector3.Slerp (riseRelCenter, setRelCenter, fracComplete);
gemToMove.transform.position += center;
}
public void MoveNegGem(Gem gemToMove,Vector3 toPos,Vector3 fromPos)
{
Vector3 center = (fromPos + toPos) * .5f;
center -= new Vector3 (0, 0,- .1f);
Vector3 riseRelCenter = fromPos - center;
Vector3 setRelCenter = toPos - center;
float fracComplete = (Time.time - startTime) / SwapRate;
gemToMove.transform.position = Vector3.Slerp (riseRelCenter, setRelCenter, fracComplete);
gemToMove.transform.position += center;
}
public void TogglePhysics(bool isON)
{
for (int i=0;i<gems.Count; i++)
{
gems*.GetComponent().isKinematic = isON;*
}
}
public void SwapGems(Gem currentGem)
{
if (lastGem == null)
{
lastGem = currentGem;
} else if (lastGem == currentGem)
{
lastGem = null;
} else {
if (lastGem.IsNeighborWith (currentGem))
{
gem1Start = lastGem.transform.position;
gem1End = currentGem.transform.position;
gem2Start = currentGem.transform.position;
gem2End = lastGem.transform.position;
startTime = Time.time;
TogglePhysics (true);
gem1 = lastGem;
gem2 = currentGem;
isSwapping = true;
}
else
{
lastGem.ToggleSelector ();
lastGem = currentGem;
}
}
}
}
I know u probably wonāt see this but this shit worked thank you