- Home /
Question by
nzmichael118 · Sep 12, 2017 at 11:29 PM ·
c#script.unityeditorscorescore system
Scoring Points.
Growing script I want the else part add a score to my text using System.Collections; using System.Collections.Generic; using UnityEngine;
public class Size_Changer : MonoBehaviour
{
public Vector3 maxLocalScale;
float maxlocalScaleMagnitude;
int milliseconds = 20000;
void Start()
{
maxLocalScale = new Vector3(0.1F, 1, 0.1F);
maxlocalScaleMagnitude = maxLocalScale.magnitude;
}
void LateUpdate()
{
float actualLocalScaleMagnitude = transform.localScale.magnitude;
if (actualLocalScaleMagnitude < maxlocalScaleMagnitude)
{
transform.localScale += new Vector3(0.0005F, 0.001F, 0.0005F);
}
else
{
Destroy(gameObject);
}
}
}
Comment
Answer by toddisarockstar · Sep 13, 2017 at 04:18 AM
seems you are destroying this script so its not a good place to keep a score. make another script attached to the camera or somewhere it cant be destroyed and put a static variable in the new script like this:
//static variables are accessable from anywhere!!
public static int score;
now simply change your score like this inside your grow script:
else
{
nameofotherscript.score++;
print("your score is now:"+ nameofotherscript.score);
Destroy(gameObject);
}