[Unity 3D] 随时注意的点(日常更新)

1. create C# file

注意文件名要与类名相同。如果没有相符的话,当脚本在游戏中运行时会出现类定义错误(class definition error)。可以在unity3D中创建C# scripts时直接更名, 也可以后面rename(右键)。

2. error MSB3644: 找不到 .NETFramework,Version=v4.7.1 的參考組件


解决办法:下载指定版本的.NETFramework, 就算下载最新版的4.7.2也不行,必须是报错提示上的

3. 属性修改权限

以position为例, 右键找到peek->Definition,出现以下界面:
在这里插入图片描述
有的属性下的list中getset都有,有的仅有get。 仅有get表示只读, 有set的话表示可修改。

3. How Unity3D excutes codes

不同与在其他开发环境以main()作为起始函数,在U3D中一个场景第一次开始时,将运行Start()函数。如果我们想在每一帧重复我们的代码,那么我们将使用Update()方法。

4. megabyte & gigabyte

When you talk about computer storage you use the word megabyte or gigabyte. The word mega refers to how many millions of bytes a component in your computer can store. Giga indicates how every many billions of bytes are being stored.

MLA (Modern Language Assoc.) Okita, Alex. Learning C# Programming with Unity 3D, Second Edition. Vol. Second edition, A K Peters/CRC Press, 2020.

5. double & float

在unity中, Vector3 由三个float类型组成,而不是double。

float floatNum = 1.0f; //32bits
double doubleNum = 1.0; //64bits
Vector3 Myvector = new Vector3(1.0, 1.0, 1.0); //error
Vector3 Myvector = new Vector3(1.0f, 1.0f, 1.0f); //correct

6. converting from a string to a number value

string s = "234834";
int i = (int) s; //ERROR
int i = int.Parse(s); //Bingo

7. #region & #endregion

#region lets you specify a block of code that you can expand or collapse when using the outlining feature of the code editor. In longer code files, it is convenient to be able to collapse or hide one or more regions so that you can focus on the part of the file that you are currently working on. The following example shows how to define a region:

#region MyClass definition  
public class MyClass
{  
    static void Main()
    {  
    }  
}  
#endregion

A #region block must be terminated with a #endregion directive.
A #region block cannot overlap with a #if block. However, a #region block can be nested in a #if block, and a #if block can be nested in a #region block.

8. out

out parameter modifier - doc

9. GetMouseButton()

GetMouseButton(0): left mouse button is pressed
GetMouseButton(1): right mouse button is pressed

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值