请问一下,为什么我击中带”enemy“的物体后,只有第一次得分是有加上去的,之后就固定在1分了,在怎么击中都没有用了。这是什么问题呢?解决方法是什么呢?刚学不久,请指教。
这是代码:
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class Score : MonoBehaviour
{
public int score = 0;
public Text scoreText;
void Start()
{
scoreText = GameObject.Find("Score Text").GetComponent<Text>();
}
// Update is called once per frame
void Update()
{
}
private void OnTriggerEnter(Collider other)
{
if(other.gameObject.tag == "enemy")
{
score++;
scoreText.text = "得分:" + score;
}
}
}
你是不是想写for循环来着,你这个是if判断,只会执行一次呀