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;
public int ammoLeft = 20;
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);
}
void Update()
{
}
}