Unity 笔试题分享

1. 请回答以下代码片段执行时是否会产生堆内存分配

a.

csharp 复制代码
  void SetChar(string s)
    {
        s.Replace('b', 'd');
    }

b.

csharp 复制代码
void Update(Transform t)
    {
        t.localPosition = new Vector3(0, 0, 0);
    }

c、

csharp 复制代码
    int Sum(List<int> l)
    {
        int total = 0;
        foreach (int i in l)
        {
            total += i;
        }      
        return total;
	}

d、

csharp 复制代码
 void SetValueAt(List<object> l, int index, int value)
    {
        if (index < 0 || index >= l.Count) {
            return;
        }

        l[index] = value;
	}
  1. A 会产生新的字符串 ,会产生
  2. B 用了New关键字 ,会产生
  3. C 会创建迭代器 ,会产生
  4. D 产生装箱操作 ,会产生

2、以下代码会产生什么样的输出

csharp 复制代码
 IEnumerator Test1()
    {
        Debug.Log("A");
        yield return Test2(); 
       
        Debug.Log("B");
        yield return null;

        Debug.Log("C");
    }

    IEnumerator Test2()
    {
        Debug.Log("D");
        yield break;

        Debug.Log("E");
    }

    void Start()
    {
        StartCoroutine(Test1());
	}

ADBC

3、请用数学公式描述如何计算向量V的反射向量R(V和N都是单位向量)

做如下辅助线

  1. V · N = |V||N|cos(θ ) = cos(θ )
  2. P = |V| * cos(θ ) * N =( V · N)* N
  3. R = R' = 2P - V = 2(V · N)N - V
相关推荐
Artistation Game1 天前
九、怪物行为逻辑
游戏·unity·游戏引擎
百里香酚兰1 天前
【AI学习笔记】基于Unity+DeepSeek开发的一些BUG记录&解决方案
人工智能·学习·unity·大模型·deepseek
妙为1 天前
unreal engine5制作动作类游戏时,我们使用刀剑等武器攻击怪物或敌方单位时,发现攻击特效、伤害等没有触发
游戏·游戏引擎·虚幻·碰撞预设
dangoxiba1 天前
[Unity Demo]从零开始制作空洞骑士Hollow Knight第十三集:制作小骑士的接触地刺复活机制以及完善地图的可交互对象
游戏·unity·visualstudio·c#·游戏引擎
先生沉默先2 天前
使用Materialize制作unity的贴图,Materialize的简单教程,Materialize学习日志
学习·unity·贴图
十画_8242 天前
Visual Studio 小技巧记录
unity·visual studio
red_redemption2 天前
cpp,git,unity学习
git·unity·游戏引擎
tealcwu2 天前
【Unity踩坑】Unity更新Google Play结算库
unity·游戏引擎
先生沉默先2 天前
unity 默认渲染管线材质球的材质通道,材质球的材质通道
unity·游戏引擎·材质
白鹭float.2 天前
【Unity AI】基于 WebSocket 和 讯飞星火大模型
人工智能·websocket·unity