查看: 1194|回复: 0
打印 上一主题 下一主题

[脚本章节]Overview: Vectors 向量

[复制链接]

3795

主题

2

听众

5万

积分

版主

Rank: 7Rank: 7Rank: 7

纳金币
53202
精华
32

活跃会员 优秀版主 推广达人 突出贡献 荣誉管理 论坛元老

跳转到指定楼层
楼主
发表于 2012-10-11 10:22:46 |只看该作者 |倒序浏览
Unity uses the Vector3 class throughout to represent all 3D vectors. The individual components of a 3D vector can be accessed through its x, y and z member variables.
Note: This only works on JavaScript and Boo. In C# you will have to create a new instance of a Vector and assign it. var aPosition : Vector3;
Unity使用 Vector3 类来表现所有的3D向量.我们可以通过他的x,y和z成员变量获得3D向量的组件.
var aPosition : Vector3 ;

aPosition.x = 1;

aPosition.y = 1;

aPosition.z = 1;
You can also use the Vector3 cons***ctor function to initialise all components at once.
你也能使用 Vector3 构造函数初始化所有的组件.


    C#
    JavaScript


using UnityEngine;using System.Collections;public class example : MonoBehaviour {public Vector3 aPosition = new Vector3(1, 1, 1);}


var aPosition = Vector3(1, 1, 1);


Vector3 also defines some common values as constants.
Vector3 也定义了一些固定的常用值.


    C#
    JavaScript


using UnityEngine;using System.Collections;public class example : MonoBehaviour {public Vector3 direction = Vector3.up;}


var direction = Vector3.up ; // 等同于 Vector3(0, 1, 0)


Operations on single vectors are accessed the following way:
规范化向量可以使用下面的方法:


    C#
    JavaScript


using UnityEngine;using System.Collections;public class example : MonoBehaviour {public void Awake() {SomeVector.Normalize();}}


SomeVector.Normalize();


And operations using multiple vectors are done using Vector3 class functions:
使用 Vector3 类函数计算多个向量的情况:


    C#
    JavaScript


using UnityEngine;using System.Collections;public class example : MonoBehaviour {public Vector3 oneVector = new Vector3(0, 0, 0);public Vector3 otherVector = new Vector3(1, 1, 1);public float theDistance = Vector3.Distance(oneVector, otherVector);}


var oneVector : Vector3 = Vector3(0,0,0);var otherVector : Vector3 = Vector3(1,1,1);var theDistance = Vector3.Distance(oneVector, otherVector);


(Note that you have to write Vector3. in front of the function name to tell Javascript where to find the function. This applies to all class functions.)
You can also use the common math operators to manipulate vectors: combined = vector1 + vector2;
See the documentation on the Vector3 class for the full list of operations and properties available.
(注意你必须在函数名之前写上Vector3.以便Javascript能找到那个函数.这个规则也应用于所有的类函数.)
你也能使用常见的数学运算操作向量:combined = vector1 + vector2;
查看文档 Vector3 类可以获得更过相关信息.



来源:unity3d圣典 更多分享尽在web3D纳金网http://www.narkii.com/



————————————————————————


Subsections 章节

     [脚本章节]Scripting Overview 脚本概述
    [脚本章节]Overview: Script compilation 脚本编译(高级)
    [脚本章节]Overview: Performance Optimization 性能优化
    [脚本章节]Overview: The most important classes 重要的类
    [脚本章节]Overview : Writing Scripts in C# 使用C#书写脚本
    [脚本章节]Overview: Coroutines & Yield 协同程序 & 中断
    [脚本章节]Overview: Instantiate 实例
    [脚本章节]Overview: Member Variables & Global Variables 成员变量 & 全局变量
    [脚本章节]Overview: Vectors 向量
    [脚本章节]Overview: Accessing Other Game Objects 访问其他游戏物体
    [脚本章节]Overview: Accessing Other Components 访问其他组件
    [脚本章节]Overview: Keeping Track of Time 记录时间
    [脚本章节]Overview: Common Operations 常用操作
分享到: QQ好友和群QQ好友和群 腾讯微博腾讯微博 腾讯朋友腾讯朋友 微信微信
转播转播0 分享淘帖0 收藏收藏0 支持支持0 反对反对0
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

手机版|纳金网 ( 闽ICP备2021016425号-2/3

GMT+8, 2024-11-18 13:48 , Processed in 0.229431 second(s), 32 queries .

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

© 2008-2019 Narkii Inc.

回顶部