Files
unity-vr-development/CollectCoins/Assets/Scripts/InventoryScript.cs
T
xixu-me e22c5cbada Add win condition and related assets
Introduced new animations, prefabs, scripts, and textures to implement a win condition in the game. Updated InventoryScript to trigger the win state when the required coin count is reached. Added supporting assets such as win animations, GUI elements, and sound effects.
2025-04-18 20:43:43 +08:00

52 lines
1.1 KiB
C#

using UnityEngine;
using System.Collections;
public class InventoryScript : MonoBehaviour {
// Use this for initialization
public AudioClip pickupSound;
public static int coinCount = 0;
public GUIText coinCountText;
public GUITexture coinPic;
public GUIText coinGUIText;
public int winCoinCount = 20;
public GameObject winObj;
void Start () {
}
// Update is called once per frame
void Update () {
}
void pickup()
{
AudioSource.PlayClipAtPoint(pickupSound, transform.position);
coinCount++;
// 触发显示金币数量
coinGUIText.SendMessage("showTextHint", coinCount.ToString());
// 显示左下角图片和数量
showCoinCount();
if (coinCount == winCoinCount)
{
this.gameObject.GetComponent<CharacterController>().enabled = false;
this.gameObject.GetComponentInChildren<ShotScript>().enabled = false;
winObj.SendMessage("gameOver");
}
}
void showCoinCount()
{
if (!coinPic.enabled)
{
coinPic.enabled = true;
coinCountText.enabled = true;
}
coinCountText.text = coinCount.ToString();
}
}