Unity教程合集Unity基础入门分享

Unity3D基础论-UGUI高级、Application、St

2017-07-21  本文已影响37人  斗魁

OutLine:组件    给现有物体加一个边框

Shadow:组件            给现有物体添加一个阴影

布局元素:

纵横比:

Application应用程序:

设置应用程序能否后台运行

//Application.runInBackground= true;

获取当前项目中的资源文件夹(Assets)路径

//例如:需要获取资源文件夹中音频,视频,图片。。。

// C:\Users\luds\DesktopWindows--Dos

// /Users/luds/DesktopMac/Linux/Unix/...

string path =Application.dataPath;

Debug.Log (path);

应用程序的工作路径

//我们需要将程序中的某些内容进行持久化存储

string path2 =Application.persistentDataPath;

Debug.Log (path2);

判断截取多张图的方法

if (Input.GetKeyDown (KeyCode.Space)) {

string path = "/Users/luds/Desktop/";

string realPath = path + "screenshot" + ".png";

//判断某个文件是否存在

if (File.Exists (realPath)) {

int startIndex = 1;

while (true) {

realPath = path + "screenshot(" + (startIndex++) + ").png";

if (!File.Exists (realPath)) {

break;

}

}

}

获取屏幕截图

Application.CaptureScreenshot(realPath);

在浏览器中打开一个链接

// URL:统一资源定位符

//协议://主机:端口/访问的文件路径?参数=参数值&参数=参数值

Application.OpenURL("http://www.baidu.com");

退出应用程序

Application.Quit();

切换场景到Scence1

// using UnityEngine.SceneManagement;命名空间

SceneManager.LoadScene("Scence1");

//切换场景的时候一定要保证两个场景都被编译了

//在File - BuildSettinds - Add Open Scence

拓展:

String字符串  :

string str = "你好,师妹";

//字符串:一串字符

1、获取某位的字符

char c =str[1];

2、获取字符串长度

int length = str.Length;

Console.WriteLine(length)

3、比较两个字符串

int result = "he".CompareTo("halo world");

Console.WriteLine(result);

4、判断字符串中是否包含某个子串

bool contains = "hello world".Contains("lr");

5、判断是否以xxx开头

bool start = "速度与激情8".StartsWith("速度与激情");

6、判断是否以xxx结尾

bool end = "忐忑.mp3".EndsWith(".mp3");

7、获取下标,如果是字符串,获取的是第一个字符下标

int index = "hello world".IndexOf("orld"); // 7

8、从字符串中移除

"hello world".Remove(5, 2);    // "hello","helloorld"

9、将字符串转成一个字符数组

char[] cotents = "hello world".ToCharArray();

10、移除字符串前后的空格

string trimResult = "           hello world         ".Trim();

Console.WriteLine(trimResult);

2D组件:

SpriteRenderer:

属性:  Sprite:精灵图片   Color:精灵颜色   Flip: X(左右翻转) Y(上下翻转)   Material:材质 

SortingLayer:精灵层    Order In Layer:同层序号

2D物理组件:

Collider2D:  OnCollisonEnter2D(Collision2D)、OnCollisonStay2D(Collision2D)、OnCollisonExit2D(Collision2D)、OnTriggerEnter2D(Collision2D)、OnTriggerStay2D(Collision2D)、OnTriggerExit2D(Collision2D)

RigidBody2D

上一篇 下一篇

猜你喜欢

热点阅读