Unity的C#編程教程_21_用 if 條件語句設計計分程序
- 設計一個程序,用於統計得分
- 每次按下空格鍵加十分
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class AddPoints : MonoBehaviour
{
public int points = 0;
// 設置個變量存儲分數
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
if (Input.GetKeyDown(KeyCode.Space)) // 判斷按下空格鍵
{
points += 10; // 加十分
Debug.Log("Points: " + points); // 顯示分數
}
}
}