Unity:学习笔记二
第三次作业
搜素 “c# 集合类型”, 了解以下类型的使用。 不知道使用,自己复习 C++ 模板库。
- IList,列表抽象行为接口
- IList泛型接口上ICollection泛型,是所有非泛型列表的基接口。
- 官方文档:https://docs.microsoft.com/zh-cn/dotnet/api/system.collections.ilist?view=netcore-3.1
- 另外的参考:https://www.cnblogs.com/zuochengsi-9/p/4863718.html
- List<T>,泛型列表类
- List<T>类是类的泛型等效项ArrayList,通过需要大小根据需要动态增加的数组来实现泛型接口,每次数组达到限制,就会把现有容量翻倍,它提供用于对集合进行搜索、排序和操作等方法。
- 官方文档:https://docs.microsoft.com/zh-cn/dotnet/api/system.collections.generic.list-1?view=netcore-3.1#code-try-3
- ArrayList,动态任意类型数组类
- 使用大小会根据需要动态增加的数组来实现IList接口
- 官方文档:https://docs.microsoft.com/zh-cn/dotnet/api/system.collections.arraylist?view=netcore-3.1#definition
- HashSet<T> 类
- HashSet<T>类提供高性能的设置操作。 集是不包含重复元素的集合,其元素无特定顺序。不支持下标访问。
- Hashtable
- Hashtable是System.Collections命名空间提供的一个容器,用于处理和表现类似key/value的键值对
学习参考网站:https://blog.csdn.net/zcaixzy5211314/article/details/80784329
1、简答并用程序验证【建议做】
- 游戏对象运动的本质是什么?
- 游戏运动对象的本质是游戏对象Position.Rotate、Scale属性数值的变化
- 请用三种方法以上方法,实现物体的抛物线运动。(如,修改Transform属性,使用向量Vector3的方法…)
- 1. 使用Vector3
-
using System.Collections; using System.Collections.Generic; using System.Collections.Specialized; using System.Security.Cryptography; using System.Security.Cryptography.X509Certificates; using System.Threading; using UnityEngine; public class Move_position : MonoBehaviour { public Transform cube; // Start is called before the first frame update public float xSpeed = 1; public float ySpeed = 3; public float a = 2; // 加速度 void Start() { cube.position = new Vector3(0, 0, 0); } // Update is called once per frame void Update() { cube.position += Vector3.left * Time.deltaTime * xSpeed; cube.position += Vector3.up * Time.deltaTime * ySpeed; ySpeed = ySpeed - Time.deltaTime * a; UnityEngine.Debug.Log(ySpeed); } }
2. 使用transform.Translate
using System.Collections; using System.Collections.Generic; using UnityEngine; public class Move_translate : MonoBehaviour { public Transform cube; // Start is called before the first frame update public float xSpeed = 1; public float ySpeed = 3; public float a = 2; // 加速度 void Start() { } // Update is called once per frame void Update() { cube.Translate(Vector3.left * Time.deltaTime * xSpeed + Vector3.up * Time.deltaTime * ySpeed); ySpeed = ySpeed - Time.deltaTime * a; UnityEngine.Debug.Log(ySpeed); } }
3. 直接修改transform
using System.Collections; using System.Collections.Generic; using UnityEngine; public class Move_transform : MonoBehaviour { public Transform cube; // Start is called before the first frame update public float xSpeed = 1; public float ySpeed = 3; public float a = 2; // 加速度 void Start() { } // Update is called once per frame void Update() { cube.position += new Vector3(Time.deltaTime * xSpeed, Time.deltaTime * ySpeed, 0); ySpeed = ySpeed - Time.deltaTime * a; UnityEngine.Debug.Log(ySpeed); } }
- 写一个程序,实现一个完整的太阳系, 其他星球围绕太阳的转速必须不一样,且不在一个法平面上。
关于使用函数RotateAround(圆的中心,旋转轴矢量,旋转速度)
理解:关于旋转平面,圆的中心确定了旋转轴的位置,旋转平面为GameObject到旋转轴垂线所在的,垂直于旋转轴的面。
感谢TA的帮助
资源:
代码:
using System.Collections; using System.Collections.Generic; using System.Collections.Specialized; using System.Diagnostics.CodeAnalysis; using System.Security.Cryptography; using System.Threading; using UnityEngine; public class RoundSun : MonoBehaviour { // Start is called before the first frame update public Transform sun; public Transform shuixing; public Transform jinxing; public Transform earth; public Transform huoxing; public Transform muxing; public Transform tuxing; public Transform tianwangxing; public Transform haiwangxing; public Transform moon; void Start() { sun.position = Vector3.zero; shuixing.position = new Vector3(3, 0, 0); jinxing.position = new Vector3(6, 0, 0); earth.position = new Vector3(9, 0, 0); huoxing.position = new Vector3(12, 0, 0); muxing.position = new Vector3(15, 0, 0); tuxing.position = new Vector3(17, 0, 0); tianwangxing.position = new Vector3(20, 0, 0); haiwangxing.position = new Vector3(23, 0, 0); moon.position = new Vector3((float)6.5, 0, 0); } // Update is called once per frame void Update() { shuixing.transform.RotateAround(sun.position, new Vector3(0,(float)2, (float)5), 752 * Time.deltaTime); jinxing.transform.RotateAround(sun.position, new Vector3(0,(float)4, (float)7), 600 * Time.deltaTime); earth.transform.RotateAround(sun.position, new Vector3(0,(float)9, (float)8), 523 * Time.deltaTime); huoxing.transform.RotateAround(sun.position, new Vector3(0,(float)1, (float)5), 432 * Time.deltaTime); muxing.transform.RotateAround(sun.position, new Vector3(0,(float)4, (float)3), 300 * Time.deltaTime); tuxing.transform.RotateAround(sun.position, new Vector3(0,(float)12, (float)2), 245 * Time.deltaTime); tianwangxing.transform.RotateAround(sun.position, new Vector3(0,(float)8, (float)19), 195 * Time.deltaTime); haiwangxing.transform.RotateAround(sun.position, new Vector3(0,(float)4, (float)17), 100 * Time.deltaTime); earth.Rotate(Vector3.up * 30 * Time.deltaTime); moon.transform.RotateAround(earth.position, new Vector3((float)1, (float)10, 0), 500 * Time.deltaTime); } }