12 第1页 | 共2 页下一页
返回列表 发新帖
查看: 4012|回复: 11
打印 上一主题 下一主题

[经验分享] javascript基本知识(一)

[复制链接]

5552

主题

2

听众

8万

积分

首席设计师

Rank: 8Rank: 8

纳金币
-1
精华
11

最佳新人 活跃会员 热心会员 灌水之王 突出贡献

跳转到指定楼层
楼主
发表于 2011-11-15 14:20:00 |只看该作者 |倒序浏览


           不错的脚本简介文章,对unity3d代码不怎么了解的朋友比较有用!
           

           Unity offers a slew of options to choose from as far as scripting goes. You can use Javascript, C#, Boo script or a combination of the three. In reality though, scripting in Unity is slightly different than other mediums. So let’s just call it Unity script. The scripting language you choose will dictate what syntax you must use in your scripts and what methods and functions will be available to you. For a beginner the easiest medium is Javascript. For more advanced users C# offers more control and better array handling than Javascript. In this tutorial we’re going to cover some of the basic elements of scripting in Javascript with Unity. We’ll go over the most commonly used methods and techniques and the basic syntax of Javascript. Let’s get started.
         

           Javascript Variables in Unity 3
         

           The first and arguably most important topic that we’ll cover is variables and variable scope. You can think of a variable as a storage unit. Each variable is assigned a name and can hold a certain type of data. You can then access the variable later on in your script via the name that you’ve assigned. Let’s look at an example.
         

           var myFirstVariable : String;
         

           function Awake () {
         

           myFirstVariable = "Hello World!";
         

           }
         

           function Start() {
         

           //prints "Hello World!" to the console.
         

           print (myFirstVariable);
         

           }In this simple example, we declare a variable called “myFirstVariable” and tell Unity that we’re going to be using it to store a string. A string can be any form of text. Next, in the Awake function we assign the value of “Hello World!” to our variable. Finally, in the Start function we print out the variable to the Unity console.
         

           There’s a couple things to take not of here. First, notice that we declared the variable *outside* of the functions. We also used the keyword “var” to tell Unity that we’re going to be declaring the variable. Since the variable was assigned outside of the functions, we can access the variable within *all* of the functions. The variable will also be available in the Unity inspector. In other words, the variable is exposed both to the Unity inspector *and* within the script itself. In Unity these are called “member variables” They are essentially a member of the script that they are declared in.
         

           If we don’t want the variable to be exposed in the inspector we can instead declare a “private member” variable. The variable will still be available for use throughout our script, but you won’t see it within the Unity inspector panel. Let’s see how we can accomplish that.
         

           private var myFirstVariable : String;
         

           function Awake () {
         

           myFirstVariable = "This string is private to this script!";
         

           }
         

           function Start() {
         

           //prints "This string is private to this script!" to the console.
         

           print (myFirstVariable);
         

           }
           

           Pretty straightforward, right? This is an example of whats called “variable scope”. Different types of variables have different “scopes”. This means you can reveal or hide variables from other aspects of your game to keep things nicely organized and use less resources.
         
分享到: QQ好友和群QQ好友和群 腾讯微博腾讯微博 腾讯朋友腾讯朋友 微信微信
转播转播0 分享淘帖0 收藏收藏0 支持支持0 反对反对0
回复

使用道具 举报

462

主题

1

听众

31万

积分

首席设计师

Rank: 8Rank: 8

纳金币
2
精华
0

最佳新人 活跃会员 热心会员 灌水之王 突出贡献

沙发
发表于 2012-2-1 23:22:14 |只看该作者
提醒猪猪,千万不能让你看见
回复

使用道具 举报

tc    

5089

主题

1

听众

33万

积分

首席设计师

Rank: 8Rank: 8

纳金币
-1
精华
0

最佳新人 活跃会员 热心会员 灌水之王 突出贡献

板凳
发表于 2012-5-7 23:25:30 |只看该作者
都闪开,介个帖子,偶来顶
回复

使用道具 举报

   

671

主题

1

听众

3247

积分

中级设计师

Rank: 5Rank: 5

纳金币
324742
精华
0

最佳新人 活跃会员 热心会员 灌水之王 突出贡献

地板
发表于 2012-5-10 23:24:00 |只看该作者
楼主收集的可真全哦
回复

使用道具 举报

   

671

主题

1

听众

3247

积分

中级设计师

Rank: 5Rank: 5

纳金币
324742
精华
0

最佳新人 活跃会员 热心会员 灌水之王 突出贡献

5#
发表于 2012-5-20 23:19:59 |只看该作者
跑着去顶朋友滴铁
回复

使用道具 举报

   

671

主题

1

听众

3247

积分

中级设计师

Rank: 5Rank: 5

纳金币
324742
精华
0

最佳新人 活跃会员 热心会员 灌水之王 突出贡献

6#
发表于 2012-5-22 23:25:10 |只看该作者
都闪开,介个帖子,偶来顶
回复

使用道具 举报

462

主题

1

听众

31万

积分

首席设计师

Rank: 8Rank: 8

纳金币
2
精华
0

最佳新人 活跃会员 热心会员 灌水之王 突出贡献

7#
发表于 2012-9-19 10:00:57 |只看该作者
响应天帅号召,顶
回复

使用道具 举报

462

主题

1

听众

31万

积分

首席设计师

Rank: 8Rank: 8

纳金币
2
精华
0

最佳新人 活跃会员 热心会员 灌水之王 突出贡献

8#
发表于 2012-12-3 23:24:02 |只看该作者
佩服,好多阿 ,哈哈
回复

使用道具 举报

1023

主题

3

听众

359

积分

设计实习生

Rank: 2

纳金币
335582
精华
0

最佳新人

9#
发表于 2013-2-19 23:39:43 |只看该作者
你们都躲开,我来顶
回复

使用道具 举报

1023

主题

3

听众

359

积分

设计实习生

Rank: 2

纳金币
335582
精华
0

最佳新人

10#
发表于 2013-2-27 23:18:10 |只看该作者
很有心,部分已收录自用,谢谢
回复

使用道具 举报

12 第1页 | 共2 页下一页
返回列表 发新帖
您需要登录后才可以回帖 登录 | 立即注册

关闭

站长推荐上一条 /1 下一条

手机版|纳金网 ( 闽ICP备08008928号

GMT+8, 2024-5-14 13:27 , Processed in 0.084711 second(s), 28 queries .

Powered by Discuz!-创意设计 X2.5

© 2008-2019 Narkii Inc.

回顶部