UnityAPI手册-2019.4官网版
文集大纲加载中……
本文档使用 MrDoc 发布
-
+
首页
Vector3.y
# [Vector3](https://docs.unity3d.com/cn/2019.4/ScriptReference/Vector3.html).y public float **y** ; ## 描述 向量的 Y 分量。 ``` // Attach this script to a GameObject // Create two Input Fields in the Scene (Create>UI>Input Field) // Click on the GameObject and attach both Input Fields in the Inspector window using UnityEngine; using UnityEngine.UI; public class ExampleClass : MonoBehaviour { Vector3 m_NewPosition; // Attach these in the Inspector window public InputField m_InputFieldX, m_InputFieldY; // These are the strings that are returned from the InputFields string xString, yString; // These are used when converting the strings to floats float m_XValue, m_YValue; void Start() { // Initialise the vector m_NewPosition = new Vector3(0.0f, 0.0f, 0.0f); } void Update() { // Store the inputs from the InputFields as strings xString = m_InputFieldX.text; yString = m_InputFieldY.text; // Convert the strings from the InputFields to floats ConvertStringsToFloats(xString, yString); // Change the NewPosition Vector's x and y components m_NewPosition.x = m_XValue; m_NewPosition.y = m_YValue; // Change the position depending on the vector transform.position = m_NewPosition; } void ConvertStringsToFloats(string XVal, string YVal) { try { // Convert the strings to floats m_XValue = float.Parse(XVal); m_YValue = float.Parse(YVal); } catch{} } } ```
da
2022年6月22日 10:53
转发文档
收藏文档
上一篇
下一篇
手机扫码
复制链接
手机扫一扫转发分享
复制链接
关于 MrDoc
觅思文档MrDoc
是
州的先生
开发并开源的在线文档系统,其适合作为个人和小型团队的云笔记、文档和知识库管理工具。
如果觅思文档给你或你的团队带来了帮助,欢迎对作者进行一些打赏捐助,这将有力支持作者持续投入精力更新和维护觅思文档,感谢你的捐助!
>>>捐助鸣谢列表
微信
支付宝
QQ
PayPal
Markdown文件
分享
链接
类型
密码
更新密码