using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class CountScoreAtWall : MonoBehaviour
{
//Varriables
public GameObject[] prefabs;
public Text animalPassedText;
public int animalPassed;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
animalPassedText.text = animalPassed.ToString();
}
void OnTriggerEnter(Collider collision)
{
if (collision.gameObject.tag == tag)
{
animalPassed = animalPassed 1;
Debug.Log("Animal Passed showed");
}
}
我想讓我的來自 Instantiate() 的克隆 Prefabs 觸摸墻壁,然后分數將增加 1 到 animalPassedText 但我不知道該怎么做。所以請幫助我。時間
uj5u.com熱心網友回復:
可能的解決方案:
1-墻壁或您的預制件都應該有一個剛體以使 OnTriggerEnter 作業。因此,請檢查您的游戲物件之一是否具有剛體并且它們都具有碰撞器。
2-也許你的“標簽”變數與collision.gameObject.tag不匹配,所以如果塊沒有被觸發。列印collision.gameObject.tag和tag以查看它們是否匹配。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/517268.html
標籤:C#unity3d
上一篇:在2D中左右移動時無法跳躍
下一篇:加載的場景元素未完全顯示
