Unity的C#编程教程_15_Variables 挑战 1

  • 尝试设置一些关于 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()
    {
        
    }
}
Tags: