using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; public class cs01 : MonoBehaviour { //移動倍率 float v1 = 0.1f; //移動距離 float dx, dy, dz = 0; //分數 int score = 0; //win sound effect public AudioClip au1; void Update() { //移動 dx = v1 * Input.GetAxis("Horizontal"); dy = v1 * Input.GetAxis("Jump"); dz = v1 * Input.GetAxis("Vertical"); this.gameObject.transform.Translate(dx, dy, dz); } //觸發 private void OnTriggerEnter(Collider other) { if(other.name== "Cylinder1" || other.name == "Cylinder2" || other.name == "Cylinder3" || other.name == "Cylinder4" || other.name == "Cylinder5") { Destroy(other.gameObject); score += 20; GameObject.Find("Tscore").GetComponent().text = "分數:" + score.ToString(); this.gameObject.GetComponent().Play(); if(score==100) { GameObject.Find("Tscore").GetComponent().text = "恭喜,過關"; this.gameObject.GetComponent().clip = au1; this.gameObject.GetComponent().Play(); } } } }