Unity的C#編程教程_15_Variables 挑戰 1
- 2020 年 7 月 29 日
- AI
- C/C++/C#
- 嘗試設置一些關於 variables 的挑戰
- 設置一個變數存儲你的名字
- 設置一個變數存儲年齡
- 設置一個變數存儲速度
- 設置一個變數存儲生命值
- 設置一個變數存儲經驗值
- 設置一個變數確認所有通關條件達成
- 設置一個變數存儲彈藥數量
- 在 console 中將這些資訊都顯示出來
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class VarTask : MonoBehaviour
{
public string playerName = "Jack Ma";
public int playerAge = 44;
public float playerSpeed = 200.0f;
public float playerHealth = 100.0f; // 血量通常以百分比形式扣減
public int playerExp = 0;
public bool getAllKeys = false; // 默認即為 false
public int ammoLeft = 20;
// Start is called before the first frame update
void Start()
{
Debug.Log("Name: " + playerName + " Age: " + playerAge + " years old");
Debug.Log("Speed: " + playerSpeed);
Debug.Log("Health: " + playerHealth);
Debug.Log("Exp: " + playerExp);
Debug.Log("Keys: " + getAllKeys);
Debug.Log("Ammo: " + ammoLeft);
}
// Update is called once per frame
void Update()
{
}
}