Question by
Internetzoo · Sep 09, 2015 at 11:13 PM ·
c#script.scriptingbasics
error CS0120: An object reference is required to access non-static member `ScoreManager.score'
using UnityEngine; using System.Collections; using UnityEngine.UI;
public class ScoreManager : MonoBehaviour { public int score;
Text text;
void Start()
{
text = GetComponent<Text> ();
score = 0f;
}
void Update ()
{
if (score < 0f)
text.text = "" + score;
}
public static void AddPoints (int pointsToAdd)
{
score += pointsToAdd;
}
public static void Reset()
{
score = 0f;
}
}
using UnityEngine;
using System.Collections;
public class CoinPickup : MonoBehaviour
{
public int pointsToAdd;
void OnTriggerEnter2D (Collider2D other)
{
if (other.GetComponent<AstromanController>() == null)
return;
ScoreManager.AddPoints(pointsToAdd);
Destroy (gameObject);
}
}
Comment
Answer by Positive7 · Sep 09, 2015 at 11:30 PM
as the Error says :
public int score;
should be
public static int score;
Your answer
Follow this Question
Related Questions
Could someone translate these to c#? 1 Answer
Need help to put together 2 scripts 0 Answers
Need to Change this script function , please 0 Answers
How can I assign swipe positions to the array as parameters? 0 Answers
Activating Scripts in another Script? 2 Answers