标签:htm ack mon space unity target baidu targe att
4-Unity中的C#编程 - 零基础(Unity 2017)
print只能在组件里面输出。==》继承了MonoBehaviour的脚本才能用。
Debug.Log();
Debug.LogWarning();
Debug.LogError();
变量的定义
数据和数据类型
http://www.cnblogs.com/tonney/archive/2011/03/18/1987577.html
运算符
https://wenku.baidu.com/view/93c32317a76e58fafab00341.html
19-枚举类型:
using System;
namespace MeiJu
{
enum RoleType
{
Mag,
Soldier,
Wizard
}
class Program
{
static void Main(string[] args)
{
RoleType rt = RoleType.Soldier;
Console.WriteLine(rt);
Console.ReadKey();
}
}
}
22-类的创建、声明和构造
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class LearnCsharp2 : MonoBehaviour {
void Start() {
int hp = 100;
//利用类声明的变量,可以叫做对象
//Enemy enemy1 = new Enemy();//构造对象
//Enemy enemy1 = null;
//print(enemy1);
Enemy enemy1 = new Enemy();
print(enemy1.name);
print(enemy1.hp);
enemy1.name = "玛丽";
print(enemy1.name);
Enemy enemy2 = new Enemy();
enemy2.name = "小二";
print(enemy1.name + " - " + enemy2.name);
enemy1.Move();
enemy2.Move();
}
}
class Enemy {
public string name;//public的字段才可以通过对象访问
public int hp;
public void Move() {
Debug.Log(name + "正在移动");
}
public void Attack() {
Debug.Log("正在攻击");
}
}
第一阶段:基础 4-Unity中的C#编程 - 零基础(Unity 2017)
标签:htm ack mon space unity target baidu targe att
原文地址:https://www.cnblogs.com/kerven/p/9045773.html