我嘗試在unity3d c#中實現一個評分系統,但它似乎沒有任何反應我已經添加標籤到對象是它附加腳本,並沒有錯誤,但我嘗試添加分數或其他沒有改變。 我有對象和對撞機元素活躍 但是當玩家碰撞其破壞對象,但它不添加比分錢和水嘗試添加比分錢或水的錯誤
這是觸發代碼
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
public class waterpicks : MonoBehaviour {
void OnTriggerEnter ( Collider other ){
if (other.tag == "water_bottle1") {
scoreManager.money += 10;
scoreManager.score += 10;
scoreManager.water += 1;
Destroy(other.gameObject);
}
}
}
,這是我的評分系統
using UnityEngine;
using UnityEngine.UI;
using System.Collections;
public class scoreManager : MonoBehaviour {
public static int score;
public static int money;
public static int level;
public static int water;
public static int drinks;
public Text ShowScore;
public Text Showmoney;
public Text Showlevel;
public Text Showwater;
//public static int frutoscoleta;
// Use this for initialization
void Start() {
score = 0;
money = 0;
level = 0;
water = 80;
//PlayerPrefs.GetInt ("scorePref");
//score = PlayerPrefs.GetInt ("scorePref");
//PlayerPrefs.GetInt ("moneyPref");
//money = PlayerPrefs.GetInt ("moneyPref");
//PlayerPrefs.GetInt ("levelPref");
//level = PlayerPrefs.GetInt ("levelPref");
ShowScore.text = "Score : " + score;
Showmoney.text = "Money : " + money;
Showlevel.text = "Level : " + level;
Showwater.text = "Drinks : " + drinks;
}
// Update is called once per frame
void Update() {
//PlayerPrefs.SetInt ("scorePref", score);
//PlayerPrefs.SetInt ("moneyPref", money);
//PlayerPrefs.SetInt ("level", level);
//scoreManager.score++;
//scoreManager.money++;
//scoreManager.level++;
}
}
你是什麼意思,什麼都沒有發生? – z3nth10n
@Ikillnukes我的意思是玩家碰撞瓶子的水應該破壞物品瓶子,然後添加10分10分和1分的飲料。但是,我的玩家與她所銷燬的瓶子發生碰撞,但是沒有在這種情況下添加其他腳本中的變量的指針scoreManager.cs – ines
你怎麼知道錢沒有被添加?調試?? – z3nth10n