- rotation是什么类型的 让一个物体旋转 45,90,90 代码的书写
四元数类型 transform.rotation=Quaternion.euler(45,90,90); - 触发和碰撞的区别和联系 tag 和层的用法
区别:触发需要勾选Is Trigger 可以穿透 tag多用于触发和碰撞,层多用于射线. - 详细列举在函数生命周期中几个重要的方法
生命周期表 Awake OnEnable Start FixedUpdate Update LateUpdate OnGUI
OnApplicationPause OnDisable OnDestory OnApplicationQuit - 实例化物体 instantiate() 参数有几个 若一个参数返回类型是什么 三个参数返回类型有几个
可以一个参数也可以三个参数 参数类型为 object vector3 rotation - 对一个按钮动态添加响应事件的代码
gameobject.GetComponent<button>().Addlisten(方法);
- 协同可以传递参数吗? 参数类型是什么
可以传递 类型为object - 在碰撞检测中我们是怎么样判断是哪种物体进入我的碰撞里面
通过tag进行判断 对象名字也可以 - 如何捕捉在程序运行时候的错误
try catch - 假如一个方法有三个主要的逻辑 我们是写三个方法还是都堆在一起 为什么
写三个方法 原因优化速度 便于日后的维护 - 脚本动态挂载代码 脚本禁用代码
enabled组件的激活 禁用 SetActive 是 GameObject中的方法用来激活 禁用游戏对象. - 扇形攻击代码
public Transform Target;
private float SkillDistance = 5;//扇形距离
private float SkillJiaodu = 60;//扇形的角度
void LateUpdate()
{
float distance = Vector3.Distance(transform.position, Target.position);
Vector3 norVec = transform.rotation * Vector3.forward * 5;
Vector3 temVec = Target.position - transform.position;
Debug.DrawLine(transform.position, norVec, Color.red);
Debug.DrawLine(transform.position, Target.position, Color.green);
float jiajiao = Mathf.Acos(Vector3.Dot(norVec.normalized, temVec.normalized)) * Mathf.Rad2Deg;//计算两个向量间的夹角
if (distance < SkillDistance)
{
if (jiajiao <= SkillJiaodu * 0.5f)
{
Debug.Log("在扇形范围内");
}
}
}
public bool UmbrellaAttact( Transform attacker ,Transform attacked ,float angle, float radius)
{
Vector3 deltaA = attacked.position - attacker.position;
float tmpAngle = Mathf.Acos(Vector3.Dot(deltaA.normalized, attacker.forward)) * Mathf.Rad2Deg;
if (tmpAngle < angle * 0.5f && deltaA.magnitude < radius)
{
return true;
}
return false;
}
- 寻路导航停止开始的代码
private NavMeshAgent _agent;
void start()
{
_agent = GetComponent<NavMeshAgent>();
}
void update()
{
_agent.isStopped=true;
_agent.isStopped=false;
}
-
导航系统中 加速度和速度之间的关系 当速度远大于加速的时候会出现不能在预定位置进行停止操作
-
写出得到某一个层的两种方式 1<<X
LayerMask.GetMask(""); -
Input.GetAxisRow 和 Input.GetAxis区别
GetAxisRaw不使用平滑滤波器
就是说GetAxis可以返回-1到1之间的数,比如检测到按键按下的时候,由0不断增加过渡到1
GetAxisRaw只能返回-1,0,1三个值 -
怎么样给一个按钮动态添加脚本
GetComponent<Button>().OnCLick.AddListenser(方法void ())
- indexoutofrange 这个是什么错误? 应该怎么样去排查
首先看看下表有没有出界 再看看你这个脚本是不是多挂载了…
超出索引范围 - 写出摄像机跟随的代码
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class MainCameraCtr : MonoBehaviour {
public int Speed;//定义速度变量
public Transform TagTransform;//要跟随的物体
private Vector3 offset;//一个向量,即摄像机与物体间的差值
// Use this for initialization
void Start () {
Speed = 5;//定义速度为5
offset = transform.position - TagTransform.position;//摄像机与物体间的差值
}
// Update is called once per frame
void Update () {
}
void LateUpdate()
{
Vector3 newpos = TagTransform.position + offset;//摄像机新的位置信息为跟随物体的坐标+差值
//线性插值,在 Speed * Time.deltaTime摄像机位置移动从之前位置开始到newpos结束
transform.position = Vector3.Lerp(transform.position, newpos, Speed * Time.deltaTime);
}
}
- 什么是多态?在Unity中那些方面我们可以用到
多态:(不同对象调用相同的方法,具有不同的行为)
继承:子类使用父类的方法
(区别)
多态:父类使用子类的方法
例子:
class Father
{
public int getEat(){
}
class Son:Father
{
public override int getEat()
{
return 0;
}
static void Main (string [] args){
Son s=new Son;
Console.WriteLine(s.getEat());
}
- 请写出写文件和读文件的简单逻辑代码
文件读写
测试题目总结
1. 1、1、2、3、5、8、13、21、34… 求第30位数是多少
2. using System;
3. namespace kaoshiti
4. {
5. class Program
6. {
7. static void Main(string[] args)
8. {
9. Console.WriteLine(num(30));
10. Console.ReadLine();
11. }
12. public static int num(int i)
13. {
14. if (i <= 0)
15. {
16. return 0;
17. }
18. else if(i>0&&i<=2)
19. {
20. return 1;
21. }
22. else
23. {
24. return num(i - 1) + num(i - 2);
25. }
26. }
27. }
class Program
{
static void Main(string[] args)
{
int[] a = new int[30];
a[0] = 1;
a[1] = 1;
for (int i = 2; i < 30; i++)
{
a[i] = a[i - 1] + a[i - 2];
}
Console.WriteLine(a[29]);
Console.ReadKey();
}
}
2. 实现一个冒泡排序法
static void Main()
{
Sort(7,3,8,2);
}
private static void Sort(params int[] array)
{
int temp = 0;
for (int i = 0; i < array.Length-1; i++)
{
for (int j = 0; j < array.Length -1-i; j++)
{
if (array[j] > array[j+1])
{
temp = array[j];
array[j] = array[j + 1];
array[j + 1] = temp;
}
}
}
foreach (int elements in array)
{
Console.WriteLine(elements);
}
}
3. 什么是装箱和拆箱
装箱:将某类型转换成 object 或者接口类型的一个过程。(当 CLR 对值类型进行装箱时,会将该值包装为 System.Object 类型,再将包装后的对象存储在堆上。)
拆箱:Obj类型转换为原类型
4. string str = null 与 string str = “” 的区别是什么?
- String str=null没有分配内存,String str=""分配了内存
- String str=null 这个引用指向了一个null ,没有地址没有值
- String str="" 这个引用指向了一个地址,地址里面存的是空的字符
5. 面向对象编程的三大特性是什么
封装 继承 多态
6. 实现一个多态
通过继承实现的不同对象调用相同的方法,表现出不同的行为,称之为多态。
class Program
{
static void Main(string[] args)
{
Animal[] a = { new Cat(), new Dog(), new Pig() };
for (int i = 0; i < a.Length; i++)
{
a[i].Bark();
a[i].Drink();
a[i].Eat();
}
Console.ReadLine();
}
}
abstract class Animal
{
public abstract void Bark();
public void Eat()
{
Console.WriteLine("动物可以吃东西");
}
public void Drink()
{
Console.WriteLine("动物可以喝水");
}
}
class Cat : Animal
{
public override void Bark()
{
Console.WriteLine("猫喵喵的叫");
}
}
class Pig : Animal
{
public override void Bark()
{
Console.WriteLine("猪哼哼的叫");
}
}
class Dog : Animal
{
public override void Bark()
{
Console.WriteLine("狗汪汪的叫");
}
}
7. 实现对方法 Method()的重载
public static int Method(int num1, int num2)
{
return num1 + num2;
}
public static double Method (double num1, double num2)
{
return num1 + num2;
}
8. 接口和抽象类的区别和联系
抽象类是定义,
接口是规范。
• 1、都可以被继承
• 2、都不能被实例化
• 3、都可以包含方法声明
• 4、派生类必须实现未实现的方法
区别
• .当在差异较大的对象间寻求功能上的共性时,使用接口;当共性较多的对象间寻求功能上的差异时,使用抽象类。
• .如果要创建组件的多个版本,建议使用抽象类。如果设计小而简练的功能块,则使用接口。
• 类是对对象的抽象,可以把抽象类理解为把类当作对象,抽象成的类叫做抽象类.而接口只是一个行为的规范或规定
9. 请针对DemoClass写出其构造函数与其重载,并简述什么时候采用无参数的构造函数什么时候采用有参数的构造函数
- 构造函数具有与类相同的名称
修饰符 返回值类型 函数名(参数类型 参数名) - 方法重载
在同一个类里 方法名称相同
方法参数列表不同(个数 类型 顺序)
class DemoClass
{
public int x, y;
public string s;
// 默认构造函数
public DemoClass()
{
x = 0;
y = 0;
}
//带参数的构造函数
public DemoClass(string a)
{
this.s=a;
}
//重载
public static int DemoClass(int a , int b)
{
return a + b;
}
public static double DemoClass(double a ,double b)
{
return a + b;
}
}
-
switch和if语句的作用与区别
判断语句,指定一个或多个要评估或测试的条件,以及条件为真时要执行的语句(必需的)和条件为假时要执行的语句(可选的)。
swich适合使用在固定值,不能进行逻辑判断 而if适合使用逻辑判断,且里面的内容多样,可以是字符串,数值等等 -
字符串可以被修改吗?
不能,字符串是常量,一但被赋值,就不能被改变。 -
List和ArrayList的区别
List 是针对特定类型、任意长度的。
ArrayList 是针对任意类型、任意长度的。
ArrayList 是通过存储 object 实现任意类型的,所以使用时要转换(使用时会出现装箱与拆箱,所以尽量避免使用)。 -
遍历数组最好使用什么 遍历list最好使用什么
Foreach for -
请写出读文件的两种固定格式
using (StreamReader reader = new StreamReader(path, Encoding.UTF8));
FileStream readFileStream = new FileStream(filePath,FileMode.Open,FileAccess.Read); -
用代码实现封装
public class cat
{
private string name;
public string Getname() //读方法
{
return name;
}
public void Setname(string aa) //写方法
{
name = aa;
}
static void Main(string[] args)
{
cat a = new cat(); //将cat类实例化
a.Setname("咪咪");
Console.WriteLine(a.Getname());
}
}
-
请写出MonoBehavior中的脚本生命周期
Awake ——OnEnable ——start ——fixedupdate ——update ——lateUpdate——OnGUI——OnApplicationPause ——OnDisable ——OnDestroy ——OnApplicationQuit -
得到组件/添加组件的完整代码(组件名称随意写)
Private rigidbody _rig;
_rig= GetComponent();
_rig=gameObject.AddComponent(); -
float f = 15.5f int i = (int)f string str = “aaa”; char c = (char)str? 对吗?
char c = (char)str不对,无法将string转化成char; -
触发的三个代码 完整的写出 方法名称 参数
void OnTriggerEnter(Collider other)
void OnTriggerStay(Collider other)
void OnTriggerExit(Collider other) -
那句代码是在加载场景的时候不销毁
DontDestoryOnLoad -
写出扇形攻击的代码
public bool UmbrellaAttact(Transform attacker, Transform attacked, float angle, float radius)
{
Vector3 deltaA = attacked.position - attacker.position; //被攻击者减去攻击者 得到向量
float tmpAngle = Mathf.Acos(Vector3.Dot(deltaA.normalized, attacker.forward)) * Mathf.Rad2Deg;
if (tmpAngle < angle * 0.5f && deltaA.magnitude < radius)
{
return true;
}
return false;
}
-
写出四元数中常见的方法至少五种
Quaternion.Angle(Quaternion a, Quaternion b); 计算两个旋转之间的夹角
Quaternion.AngleAxis(float angle, Vector3 axis); 将物体绕axis旋转angle度
Quaternion LookRotation(Vector3 forward); 建立一个旋转,使z轴朝向forward y轴朝向upwards
Quaternion.Euler(float x, float y, float z); 把旋转角度变成对应的Quaternion,返回一个先沿z轴旋转z角度,然后沿x轴旋转x角度,最后沿y轴旋转y角度的旋转
Quaternion.Inverse (Quaternion rotation); 返回反向的旋转 -
如何在update里面进行间隔计时 写出实现的方法
Update() 中 不断加Time.timeScale 然后到了 x秒相应什么事件
时间控制 -
冻结刚体旋转的代码
_rig.constraints =RigidbodyConstraints.FreezeRotationX | RigidbodyConstraints.FreezeRotationZ | RigidbodyConstraints.FreezePositionX; -
从屏幕发射射线的代码
Ray myRay=Camera.main.ScreenPointRay; -
射线检测的代码
Raycasthit hit;
If(Physics.Raycast(myRay,out hit)) -
UGUI动态绑定事件的代码
gameobject.GetComponent().Addlisten(方法); -
导航层的作用
-
什么情况下scene视图看不到物体但是game视图却看的到
Layers层该物体的图层被隐藏 -
列举字典场景的几种方法和怎样遍历字典
(1)KeyValuePair foreach (KeyValuePair<string, int> pair in dic)
(2)Dictionary.Values foreach (int value in dic.Values)
(3)Dictionary.Keys foreach (string key in dic.Keys) -
制作 登录 注册 数据从txt文件中 txt文件用户名称为 userName userPasswd 完成之后进行异步场景跳转到场景2
-
在场景中控制人物移动 鼠标转向控制旋转 摄像机跟随移动
2.1: 在该场景中有4个怪物出生点 场景中的怪物能够进行跟随 当符合一定距离要求对玩家进行间隔伤害
2.2: 玩家只能对在自身60度范围的敌人进行攻击伤害(Q键进行伤害)
2.3: 在玩家受伤害的时候会出现屏幕闪烁 血条减少
2.4: 敌人伤害的时候会出现伤害特效 若敌人死亡的时候 屏幕左下角出现玩家相对怪物的坐标信息
2.5: 敌人死亡为3的倍数的时候回随机掉落两种包 一种红色(场景的敌人都死亡) 一种绿色(满血)
2.6: 屏幕右上角显示红和绿的数量
2.7: 空格键释放红 p键释放绿
2.8: 要有对应的分数显示 要求分数持久化存储!